top
Loading...
ASP.NET2.0GridView綁定XmlDocument
ASP.NET 2.0提供了多種數據源,一般情況下,XmlDataSource控件使用XML文件,下面的例子就是使用XmlDocument對象進行數據綁定的一種方法。

VB.NET代碼

<%@ Page Language="VB" %><script runat="server"> Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Dim doc As New System.Xml.XmlDocument doc.Load("http://dotnet.aspx.cc/Rss.aspx") XmlDataSource1.Data = doc.InnerXml XmlDataSource1.XPath = "/rss/channel/item" End Sub</script><html xmlns="http://www.w3.org/1999/xhtml"><body> <form id="form1" runat="server"> <Columns> <ItemTemplate> '> <%#XPath("title")%></asp:HyperLink> [<%#CType(XPath("pubDate"), DateTime).ToString("yyyy年M月d日")%>] </ItemTemplate> </asp:TemplateField> </Columns> </asp:GridView> </asp:XmlDataSource> </form></body></html>

C#代碼

<%@ Page Language="C#" AutoEventWireup="true"%><script runat="server"> protected void Page_Load( object sender, System.EventArgs e ) { System.Xml.XmlDocument doc = new System.Xml.XmlDocument(); doc.Load("http://dotnet.aspx.cc/Rss.aspx"); XmlDataSource1.Data = doc.InnerXml; XmlDataSource1.XPath = "/rss/channel/item"; }</script><html xmlns="http://www.w3.org/1999/xhtml"><body> <form id="form1" runat="server"> <Columns> <ItemTemplate> '> <%#XPath("title")%></asp:HyperLink> [<%#(DateTime.Parse(XPath("pubDate").ToString().Replace("GMT",""))).ToString("yyyy年M月d日")%>] </ItemTemplate> </asp:TemplateField> </Columns> </asp:GridView> </asp:XmlDataSource> </form></body></html>
作者:http://www.zhujiangroad.com
來源:http://www.zhujiangroad.com
北斗有巢氏 有巢氏北斗