国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 編程 > .NET > 正文

ASP.NET2.0 GridView綁定XmlDocument

2024-07-10 13:09:52
字體:
來源:轉載
供稿:網友

  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">
    <asp:gridview id="gridview1" runat="server" datasourceid="xmldatasource1" autogeneratecolumns="false">
      <columns>
        <asp:templatefield headertext="文章標題">
          <itemtemplate>
            <asp:hyperlink runat="server" target="_blank" navigateurl='<%#xpath("link") %>'>
            <%#xpath("title")%></asp:hyperlink>
            [<%#ctype(xpath("pubdate"), datetime).tostring("yyyy年m月d日")%>]
          </itemtemplate>
        </asp:templatefield>
      </columns>
    </asp:gridview>
    <asp:xmldatasource id="xmldatasource1" runat="server"></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">
    <asp:gridview id="gridview1" runat="server" datasourceid="xmldatasource1" autogeneratecolumns="false">
      <columns>
        <asp:templatefield headertext="文章標題">
          <itemtemplate>
            <asp:hyperlink id="hyperlink1" runat="server" target="_blank" navigateurl='<%#xpath("link") %>'>
            <%#xpath("title")%></asp:hyperlink>
            [<%#(datetime.parse(xpath("pubdate").tostring().replace("gmt",""))).tostring("yyyy年m月d日")%>]
          </itemtemplate>
        </asp:templatefield>
      </columns>
    </asp:gridview>
    <asp:xmldatasource id="xmldatasource1" runat="server"></asp:xmldatasource>
  </form>
</body>
</html>

發(fā)表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發(fā)表
主站蜘蛛池模板: 汉中市| 资源县| 朝阳县| 宜章县| 勃利县| 安顺市| 浠水县| 柘城县| 萍乡市| 博客| 项城市| 德昌县| 锦州市| 通州区| 临泉县| 建阳市| 广南县| 长宁区| 双柏县| 平谷区| 合水县| 文水县| 金华市| 敦化市| 集贤县| 徐水县| 财经| 改则县| 潮州市| 梅河口市| 紫阳县| 社旗县| 邢台市| 济源市| 股票| 济阳县| 惠东县| 南阳市| 襄樊市| 潜江市| 罗源县|