Programming Journal C#, Java, SQL and to a lesser extent HTML, CSS, XML, and regex. I made this so other programmers could benefit from my experience.

Tuesday, July 1, 2008

Using XML and XPath for a GridView

This demonstrates how to use XML and XPath with a GridView to display links:

<asp:GridView ID="gvLinks" runat="server" DataSourceID="XmlDataSource1" AutoGenerateColumns="False">
<Columns>
<asp:TemplateField HeaderText="Link">
<ItemTemplate>
<asp:HyperLink ID="HyperLink1" runat="server" Target="_blank" NavigateUrl='<%#XPath("href") %>'>
<%#XPath("title")%>
</asp:HyperLink>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Description">
<ItemTemplate>
<asp:Label ID="lblrOwner" runat="server" Text=&lt;%#XPath("description")%&gt;></asp:Label>
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
<asp:XmlDataSource ID="XmlDataSource1" runat="server" DataFile="~/App_Data/Links.xml"
XPath="links/link"></asp:XmlDataSource>
Here is the XML file:

<?xml version="1.0" encoding="utf-8" ?>
<links>
<link>
<title>Yahoo</title>
<href>http://www.yahoo.com/</href>
<owner>Yang</owner>
<description>Yahoo web portal</description>
</link>
<link>
<title>MSN</title>
<href>http://www.msn.com/</href>
<owner>Balmer</owner>
<description>Microsoft web portal</description>
</link>
<link>
<title>Delicious</title>
<href>http://del.icio.us/</href>
<owner></owner>
<description>Internet bookmark manager</description>
</link>
<link>
<title>YouTube</title>
<href>http://youtube.com/</href>
<owner></owner>
<description>Internet videos</description>
</link>
<link>
<title>SlashDot</title>
<href>http://slashdot.org/</href>
<owner></owner>
<description>News that matters</description>
</link>

</links>
Reference: http://bytes.com/forum/thread528704.html

3 comments:

Anonymous said...

Nude woman [url=http://www.buzka.com/faves/406601/audrina-patridge-nude] naked photos[/url] Celebrity nudes

Anonymous said...

Hi,

I begin on internet with a directory

Anonymous said...

I think this is among the most significant information for me.
And i am glad reading your article. But should remark on some general things,
The website style is wonderful, the articles is really great :
D. Good job, cheers
my webpage - diets that work