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

首頁 > 開發 > XML > 正文

分別用DataGrid、Repeater、DataList綁定XML數據的例子

2024-09-05 20:55:43
字體:
來源:轉載
供稿:網友
  • 網站運營seo文章大全
  • 提供全面的站長運營經驗及seo技術!
  • data.aspx

    <%@ import namespace="system" %>
    <%@ import namespace="system.io" %>
    <%@ import namespace="system.xml" %>
    <%@ import namespace="system.data" %>
    <%@ import namespace="system.data.ado" %>

    <script language="vb" runat=server>
    dim ds as dataset = new dataset()
       sub page_load(sender as object, e as eventargs)
          dim fs     as filestream
          dim reader as streamreader
          dim path   as string
          path = server.mappath( "books.xml" )
          fs = new filestream(path, filemode.open, fileaccess.read)
          reader = new streamreader(fs, encoding.default)
          ds.readxml(reader)
          grid1.datasource = ds.tables("book").defaultview
          grid1.databind()
          repeater1.datasource = ds.tables("book").defaultview
          repeater1.databind()
          datalist1.datasource = ds.tables("book").defaultview
          datalist1.databind()
       end sub

       sub changepage(sender as object, e as datagridpagechangedeventargs)
          grid1.datasource = ds.tables("book").defaultview
          grid1.databind()
          repeater1.datasource = ds.tables("book").defaultview
          repeater1.databind()
          datalist1.datasource = ds.tables("book").defaultview
          datalist1.databind()
       end sub

       sub datalist_itemcommand(sender as object, e as datalistcommandeventargs)
         select case e.commandsource.text
        case "詳細"
            datalist1.selectedindex = e.item.itemindex
         case "關閉"  
            datalist1.selectedindex = -1
         end select
         datalist1.datasource = ds.tables("book").defaultview
         datalist1.databind()
       end sub

    </script>
    <html>
    <head>
    </head>
    <body style="background-color:f6e4c6">
    <form runat="server">
    <p>datagrid演示</p>
    <asp:datagrid
        allowpaging="true"
        pagesize="10"
        onpageindexchanged="changepage"
        pagerstyle-horizontalalign="right"
        pagerstyle-nextpagetext="下一頁"
        pagerstyle-prevpagetext="上一頁"
        headerstyle-backcolor="#aaaadd"
        alternatingitemstyle-backcolor="#ffffc0"
        bordercolor="black"
        cellpadding="2"
        cellspacing="0"
        id="grid1" runat="server"/>

    <p>repeater演示</p>
    <table border="1">
    <asp:repeater id="repeater1" runat="server">

    <template name="headertemplate" >
    <tr align="center"><th >書名</th><th>作者</th><th>價格</th></tr>
    </template>

    <template name="itemtemplate">
    <tr><td><%# container.dataitem("title") %></td>
            <td><%# container.dataitem("last-name") %>  <%# container.dataitem("first-name") %></td>
            <td><%# container.dataitem("price") %></td>
    </tr>
    </template>

    </asp:repeater>
    </table>


    <p>datalist 演示</p>
    <asp:datalist id="datalist1" runat="server"
         border="1" bordercolor="black"
         cellpadding="2" cellspacing="0"
         headerstyle-backcolor="#888888"
         itemstyle-backcolor="#eeeeee"
         selecteditemstyle-backcolor="#ffffff"
         headertemplate-colspan="3"
         onitemcommand="datalist_itemcommand" >

    <template name="headertemplate" >

    </template>


    <!--內容模版-->
    <template name="itemtemplate">
    書名:<%# container.dataitem("title") %>
    <asp:linkbutton id="detail" runat="server" text="詳細" forecolor="#333333"/>
    </template>


    <template name="selecteditemtemplate">
    書名:<%# container.dataitem("title") %><br>
    作者:<%# container.dataitem("last-name") %>  <%# container.dataitem("first-name") %><br>
    價格:<%# container.dataitem("price") %><br>
    <div align="right"><asp:linkbutton id="title" runat="server" text="關閉" forecolor="#333333"/></div>
    </template>

    </asp:datalist>

    </form>
    </body>
    </html>


    books.xml
    <?xml version="1.0" encoding="gb2312"?>
    <newdataset>
      <xsd:schema id="newdataset" targetnamespace="" xmlns="" xmlns:xsd="http://www.w3.org/1999/xmlschema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
        <xsd:element name="book">
          <xsd:complextype content="elementonly">
            <xsd:all>
              <xsd:element name="title" minoccurs="0" type="xsd:string"/>
              <xsd:element name="first-name" minoccurs="0" type="xsd:string"/>
              <xsd:element name="last-name" minoccurs="0" type="xsd:string"/>
              <xsd:element name="price" minoccurs="0" type="xsd:float"/>
            </xsd:all>
          </xsd:complextype>
        </xsd:element>
        <xsd:element name="newdataset" msdata:isdataset="true">
          <xsd:complextype>
            <xsd:choice maxoccurs="unbounded">
              <xsd:element ref="book"/>
            </xsd:choice>
          </xsd:complextype>
        </xsd:element>
      </xsd:schema>
    <!-- this file represents a fragment of a book store inventory database -->
    <bookstore>
      <book genre="autobiography" publicationdate="1981" isbn="1-861003-11-0">
        <title>the autobiography of benjamin franklin</title>
        <author>
          <first-name>benjamin</first-name>
          <last-name>franklin</last-name>
        </author>
        <price>8.99</price>
      </book>
      <book genre="novel" publicationdate="1967" isbn="0-201-63361-2">
        <title>the confidence man</title>
        <author>
          <first-name>herman</first-name>
          <last-name>melville</last-name>
        </author>
        <price>11.99</price>
      </book>
      <book genre="philosophy" publicationdate="1991" isbn="1-861001-57-6">
        <title>the gorgias</title>
        <author>
          <name>plato</name>
        </author>
        <price>9.99</price>
      </book>
      <book genre="autobiography" publicationdate="1981" isbn="1-861003-11-0">
        <title>the autobiography of benjamin franklin</title>
        <author>
          <first-name>benjamin</first-name>
          <last-name>franklin</last-name>
        </author>
        <price>8.99</price>
      </book>
      <book genre="autobiography" publicationdate="1981" isbn="1-861003-11-0">
        <title>the autobiography of benjamin franklin</title>
        <author>
          <first-name>benjamin</first-name>
          <last-name>franklin</last-name>
        </author>
        <price>8.99</price>
      </book>
      <book genre="autobiography" publicationdate="1981" isbn="1-861003-11-0">
        <title>the autobiography of benjamin franklin</title>
        <author>
          <first-name>benjamin</first-name>
          <last-name>franklin</last-name>
        </author>
        <price>8.99</price>
      </book>
      <book genre="autobiography" publicationdate="1981" isbn="1-861003-11-0">
        <title>the autobiography of benjamin franklin</title>
        <author>
          <first-name>benjamin</first-name>
          <last-name>franklin</last-name>
        </author>
        <price>8.99</price>
      </book>
      <book genre="autobiography" publicationdate="1981" isbn="1-861003-11-0">
        <title>the autobiography of benjamin franklin</title>
        <author>
          <first-name>benjamin</first-name>
          <last-name>franklin</last-name>
        </author>
        <price>8.99</price>
      </book>
      <book genre="autobiography" publicationdate="1981" isbn="1-861003-11-0">
        <title>the autobiography of benjamin franklin</title>
        <author>
          <first-name>benjamin</first-name>
          <last-name>franklin</last-name>
        </author>
        <price>8.99</price>
      </book>
      <book genre="autobiography" publicationdate="1981" isbn="1-861003-11-0">
        <title>the autobiography of benjamin franklin</title>
        <author>
          <first-name>benjamin</first-name>
          <last-name>franklin</last-name>
        </author>
        <price>8.99</price>
      </book>
      <book genre="autobiography" publicationdate="1981" isbn="1-861003-11-0">
        <title>the autobiography of benjamin franklin</title>
        <author>
          <first-name>benjamin</first-name>
          <last-name>franklin</last-name>
        </author>
        <price>8.99</price>
      </book>
      <book genre="autobiography" publicationdate="1981" isbn="1-861003-11-0">
        <title>the autobiography of benjamin franklin</title>
        <author>
          <first-name>benjamin</first-name>
          <last-name>franklin</last-name>
        </author>
        <price>8.99</price>
      </book>
    </bookstore>

    </newdataset>
    發表評論 共有條評論
    用戶名: 密碼:
    驗證碼: 匿名發表
    主站蜘蛛池模板: 磴口县| 荆州市| 岳西县| 郧西县| 师宗县| 蒙阴县| 泽普县| 定南县| 吉林市| 阿合奇县| 印江| 木兰县| 北京市| 浦江县| 铜鼓县| 广水市| 偃师市| 武穴市| 十堰市| 苍南县| 林西县| 威信县| 东源县| 晋城| 衡阳市| 修文县| 金溪县| 松阳县| 石城县| 潮州市| 合山市| 鲁山县| 新绛县| 弥勒县| 双峰县| 天台县| 安岳县| 辽阳县| 镇雄县| 贵州省| 富宁县|