You can use the XPath data binding expression within ItemTemplates. For
example, if you had an xml that looks like this:
<RootNode>
<Node>
<Category ID="1">
<Product ID="1" Name="Product 1">
<Supplier ID="1">Description for Supplier 1</Supplier>
<Supplier ID="2">Description for Supplier 2</Supplier>
</Product>
</Category>
</Node>
</RootNode>
and an XMLDataSource object that reads that xml like this:
<asp:XmlDataSource ID="XmlDataSourceControl1"
DataFile="~/App_Data/Products.xml"
XPath="RootNode/Node/Category[@ID='1']/Product" runat="Server" />
Then you can write a GridView with templates like this:
<asp:GridView ID="GridView1" runat="server"
DataSourceID="XmlDataSource1"
AutoGenerateColumns="false">
<Columns>
<asp:TemplateField>
<HeaderTemplate>
Product ID</HeaderTemplate>
<ItemTemplate>
<asp:Label ID="Label1" runat="server"
Text='<%#XPath("@ID")
%>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField>
<HeaderTemplate>
Product Name</HeaderTemplate>
<ItemTemplate>
<asp:Label ID="Label2" runat="server"
Text='<%#XPath("Name")
%>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField>
<HeaderTemplate>
Product Name</HeaderTemplate>
<ItemTemplate>
<asp
ataList id="SupplierDataList" DataSource='<%#
XPathSelect("Supplier") %>' runat="server">
<ItemTemplate>
<br>
<u>
Supplier ID <%# XPath("@ID") %>:
<%# XPath("@ID") %>
</u>
<br>
<%# XPath(".") %>
</ItemTemplate>
</asp
ataList>
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
--
HTH,
Phillip Williams
http://www.societopia.net
http://www.webswapp.com
:
I'm trying to find a way to bind hierarchical data to a gridview
control.
I've been able to do this with some third party controls and was
wondering if
this functionality is available with the gridview control. Does anyone
have a
guidance on this? Thanks