This demo is based on the GridView Examples for ASP.NET 2.0: Accessing Data with the DataSource Controls MSDN article. It illustrates how to bind the ASPxGridView with the XmlDataSource control.
The ASPxGridView generates its column automatically for the following XmlDataSource's structure:
[XML]<root><DataItemfield1="...".../></root>
[ASPx]<dx:GridViewDataTextColumnFieldName="field1"/>
If it's necessary to bind the ASPxGridView with the XmlDataSource whose structure is non-standard:
[XML]<root><DataItem><field1>...</field1></DataItem></root>
1) Use the XSLT technology to transform the underlying XML file in the required manner:
[XML]<?xmlversion="1.0"encoding="utf-8"?><xsl:stylesheetversion="1.0"xmlns:xsl="http://www.w3.org/1999/XSL/Transform"><xsl:templatematch="/"><items><xsl:for-eachselect="//DataItem"><itemfield1="{field1}"/></xsl:for-each></items></xsl:template></xsl:stylesheet>
2) Use the GridViewColumn's DataItemTemplate and an XPath expression:
[ASPx]<dx:GridViewDataTextColumnFieldName="field1"><DataItemTemplate><%#XPath("field1")%></DataItemTemplate></dx:GridViewDataTextColumn>
To allow ASPxGridView sorting, it's necessary to implement the IXPathNavigable interface for the ASPxGridView.DataSource's type. Please refer to the XPath Querying Over Objects with ObjectXPathNavigator MSDN article regarding this.
See Also:
How to bind ASPxGridView with Xml Document via ObjectDataSource
How to show long text in the PreviewRow using the ASPxCallback control