XmlDataSource GridView Example
Posted by Tihomir Ivanov on 11 July 2009 15:22
Rating: 0.00
Here's a simple example example of using XmlDataSource and GridView:
the xml file:
<?xml version="1.0" encoding="utf-8" ?>
<root>
<item>
<id>1</id>
<content>content 1</content>
<author>author 1</author>
</item>
<item>
<id>2</id>
<content>content 2</content>
<author>author 2</author>
</item>
<item>
<id>3</id>
<content>content 3</content>
<author>author 3</author>
</item>
</root>
in the aspx page:
<asp:GridView ID="_itemsGV" runat="server"
DataSourceID="_itemsDS"
DataFile="~/App_Data/your_file.xml"
GridLines="None"
AutoGenerateColumns="false">
<Columns>
<asp:TemplateField>
<ItemTemplate>
<%#XPath("content") %>
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
<asp:XmlDataSource ID="_itemsDS" runat="server" XPath="root/item"></asp:XmlDataSource>
That's all. I hope it'll be useful for breshing up your asp.net knowledge everytime you need to write XmlDataSource + GridView :)
didnt work for me
Object reference not set to an instance of an object.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.NullReferenceException: Object reference not set to an instance of an object.