Asp.net, vb.net, C#.net Resources
Welcome to Asp.net, vb.net, C#.net Resources
Sign in
|
Join
|
Help
in
XML (forum)
FAQs (group)
(Entire Site)
Search
Home
Blogs
Forums
Downloads
Asp.net, vb.net, C#.net Resour...
»
FAQs
»
asp.net Faqs
»
XML
»
Re: How to display the Attribute values in an XML Document in a DataGrid?
How to display the Attribute values in an XML Document in a DataGrid?
Last post 08-22-2006, 8:50 AM by
Webdeveloper
. 1 replies.
Sort Posts:
Oldest to newest
Newest to oldest
Previous
Next
08-21-2006, 6:13 AM
366
Webdeveloper
Joined on 08-19-2006
Posts 1,589
How to display the Attribute values in an XML Document in a DataGrid?
Reply
Quote
How to display the Attribute values in an XML Document in a DataGrid?
Report abuse
08-22-2006, 8:50 AM
748
in reply to
366
Webdeveloper
Joined on 08-19-2006
Posts 1,589
Re: How to display the Attribute values in an XML Document in a DataGrid?
Reply
Quote
products.xml
<?xml version="1.0" standalone="yes"?>
<NewDataSet>
<Product>
<ProductID pcode="P2">2</ProductID>
<ProductName>Chang</ProductName>
<SupplierID>1</SupplierID>
<CategoryID>1</CategoryID>
<QuantityPerUnit>24 - 12 oz bottles</QuantityPerUnit>
</Product>
<Product>
<ProductID pcode="P4">3</ProductID>
<ProductName>Aniseed Syrup</ProductName>
<SupplierID>1</SupplierID>
<CategoryID>2</CategoryID>
<QuantityPerUnit>12 - 550 ml bottles</QuantityPerUnit>
</Product>
</NewDataSet>
Use Namespace System.Xml
VB.NET
<asp:DataGrid id="DataGrid1" AutoGenerateColumns="False" runat="server">
<Columns>
<asp:TemplateColumn HeaderText="ProductCode">
<ItemTemplate>
<%#CType(Container.DataItem, System.Xml.XmlNode).Attributes("pcode").value%>
</ItemTemplate>
</asp:TemplateColumn>
</Columns>
</asp:DataGrid>
dim xmldoc as XmlDocument = new XmlDocument()
xmldoc.Load(Server.MapPath("products.xml"))
dim xmlnodes as XmlNodeList = xmldoc.SelectNodes("NewDataSet/Product/ProductID")
DataGrid1.DataSource = xmlnodes
DataGrid1.DataBind ()
C#
<asp:DataGrid id="DataGrid1" AutoGenerateColumns="False" runat="server">
<Columns>
<asp:TemplateColumn HeaderText ="ProductCode">
<ItemTemplate>
<%# ((System.Xml.XmlNode)Container.DataItem).Attributes["pcode"].Value %>
</ItemTemplate>
</asp:TemplateColumn>
</Columns>
</asp:DataGrid>
XmlDocument xmldoc = new XmlDocument();
xmldoc.Load(Server.MapPath("products.xml"));
XmlNodeList xmlnodes = xmldoc.SelectNodes("NewDataSet/Product/ProductID");
DataGrid1.DataSource = xmlnodes;
DataGrid1.DataBind ();
Report abuse
Powered by
Megasolutions ltd