多多色-多人伦交性欧美在线观看-多人伦精品一区二区三区视频-多色视频-免费黄色视屏网站-免费黄色在线

中國(guó)最全I(xiàn)T社區(qū)平臺(tái) 聯(lián)系我們 | 收藏本站
阿里云優(yōu)惠2

aspnet教程

  • ASP.NET 教程
  • ASP.NET 簡(jiǎn)介
  • ASP.NET Razor

    ASP.NET MVC

    ASP.NET 編程指南

    ASP.NET Repeater 控件

    閱讀 (2069)

    ASP.NET Web Forms - Repeater 控件


    Repeater 控件用于顯示被綁定在該控件上的項(xiàng)目的重復(fù)列表。


    綁定 DataSet 到 Repeater 控件

    Repeater 控件用于顯示被綁定在該控件上的項(xiàng)目的重復(fù)列表。Repeater 控件可被綁定到數(shù)據(jù)庫(kù)表、XML 文件或者其他項(xiàng)目列表。在這里,我們將演示如何綁定 XML 文件到 Repeater 控件。

    在我們的實(shí)例中,我們將使用下面的 XML 文件("cdcatalog.xml"):

    <?xml version="1.0" encoding="ISO-8859-1"?>

    <catalog>
    <cd>
    <title>Empire Burlesque</title>
    <artist>Bob Dylan</artist>
    <country>USA</country>
    <company>Columbia</company>
    <price>10.90</price>
    <year>1985</year>
    </cd>
    <cd>
    <title>Hide your heart</title>
    <artist>Bonnie Tyler</artist>
    <country>UK</country>
    <company>CBS Records</company>
    <price>9.90</price>
    <year>1988</year>
    </cd>
    <cd>
    <title>Greatest Hits</title>
    <artist>Dolly Parton</artist>
    <country>USA</country>
    <company>RCA</company>
    <price>9.90</price>
    <year>1982</year>
    </cd>
    <cd>
    <title>Still got the blues</title>
    <artist>Gary Moore</artist>
    <country>UK</country>
    <company>Virgin records</company>
    <price>10.20</price>
    <year>1990</year>
    </cd>
    <cd>
    <title>Eros</title>
    <artist>Eros Ramazzotti</artist>
    <country>EU</country>
    <company>BMG</company>
    <price>9.90</price>
    <year>1997</year>
    </cd>
    </catalog>

    查看這個(gè) XML 文件:cdcatalog.xml

    首先,導(dǎo)入 "System.Data" 命名空間。我們需要該命名空間與 DataSet 對(duì)象一起工作。 把下面這條指令包含在 .aspx 頁(yè)面的頂部:

    <%@ Import Namespace="System.Data" %>

    接著,為 XML 文件創(chuàng)建一個(gè) DataSet,并在頁(yè)面第一次加載時(shí)把這個(gè) XML 文件載入 DataSet:

    <script runat="server">
    sub Page_Load
    if Not Page.IsPostBack then
    dim mycdcatalog=New DataSet
    mycdcatalog.ReadXml(MapPath("cdcatalog.xml"))
    end if
    end sub

    然后我們?cè)?.aspx 頁(yè)面中創(chuàng)建一個(gè) Repeater 控件。<HeaderTemplate> 元素中的內(nèi)容被首先呈現(xiàn),并且在輸出中僅出現(xiàn)一次,而 <ItemTemplate> 元素中的內(nèi)容會(huì)對(duì)應(yīng) DataSet 中的每條 "record" 重復(fù)出現(xiàn),最后,<FooterTemplate> 元素中的內(nèi)容在輸出中僅出現(xiàn)一次:

    <html>
    <body>

    <form runat="server">
    <asp:Repeater id="cdcatalog" runat="server">

    <HeaderTemplate>
    ...
    </HeaderTemplate>

    <ItemTemplate>
    ...
    </ItemTemplate>

    <FooterTemplate>
    ...
    </FooterTemplate>

    </asp:Repeater>
    </form>

    </body>
    </html>

    然后我們添加創(chuàng)建 DataSet 的腳本,并且綁定 mycdcatalog DataSet 到 Repeater 控件。然后 使用 HTML 標(biāo)簽來(lái)填充 Repeater 控件,并通過(guò) <%#Container.DataItem("fieldname")%> 綁定數(shù)據(jù)項(xiàng)目到 <ItemTemplate> 區(qū)域內(nèi)的單元格中:

    實(shí)例

    <%@ Import Namespace="System.Data" %>

    <script runat="server">
    sub Page_Load
    if Not Page.IsPostBack then
    dim mycdcatalog=New DataSet
    mycdcatalog.ReadXml(MapPath("cdcatalog.xml"))
    cdcatalog.DataSource=mycdcatalog
    cdcatalog.DataBind()
    end if
    end sub
    </script>

    <html>
    <body>

    <form runat="server">
    <asp:Repeater id="cdcatalog" runat="server">

    <HeaderTemplate>
    <table border="1" width="100%">
    <tr>
    <th>Title</th>
    <th>Artist</th>
    <th>Country</th>
    <th>Company</th>
    <th>Price</th>
    <th>Year</th>
    </tr>
    </HeaderTemplate>

    <ItemTemplate>
    <tr>
    <td><%#Container.DataItem("title")%></td>
    <td><%#Container.DataItem("artist")%></td>
    <td><%#Container.DataItem("country")%></td>
    <td><%#Container.DataItem("company")%></td>
    <td><%#Container.DataItem("price")%></td>
    <td><%#Container.DataItem("year")%></td>
    </tr>
    </ItemTemplate>

    <FooterTemplate>
    </table>
    </FooterTemplate>

    </asp:Repeater>
    </form>

    </body>
    </html>

    演示實(shí)例 ?

    使用 <AlternatingItemTemplate>

    您可以在 <ItemTemplate> 元素后添加 <AlternatingItemTemplate> 元素,用來(lái)描述輸出中交替行的外觀。在下面的實(shí)例中,表格每隔一行就會(huì)顯示為淺灰色的背景:

    實(shí)例

    <%@ Import Namespace="System.Data" %>

    <script runat="server">
    sub Page_Load
    if Not Page.IsPostBack then
    dim mycdcatalog=New DataSet
    mycdcatalog.ReadXml(MapPath("cdcatalog.xml"))
    cdcatalog.DataSource=mycdcatalog
    cdcatalog.DataBind()
    end if
    end sub
    </script>

    <html>
    <body>

    <form runat="server">
    <asp:Repeater id="cdcatalog" runat="server">

    <HeaderTemplate>
    <table border="1" width="100%">
    <tr>
    <th>Title</th>
    <th>Artist</th>
    <th>Country</th>
    <th>Company</th>
    <th>Price</th>
    <th>Year</th>
    </tr>
    </HeaderTemplate>

    <ItemTemplate>
    <tr>
    <td><%#Container.DataItem("title")%></td>
    <td><%#Container.DataItem("artist")%></td>
    <td><%#Container.DataItem("country")%></td>
    <td><%#Container.DataItem("company")%></td>
    <td><%#Container.DataItem("price")%></td>
    <td><%#Container.DataItem("year")%></td>
    </tr>
    </ItemTemplate>

    <AlternatingItemTemplate>
    <tr bgcolor="#e8e8e8">
    <td><%#Container.DataItem("title")%></td>
    <td><%#Container.DataItem("artist")%></td>
    <td><%#Container.DataItem("country")%></td>
    <td><%#Container.DataItem("company")%></td>
    <td><%#Container.DataItem("price")%></td>
    <td><%#Container.DataItem("year")%></td>
    </tr>
    </AlternatingItemTemplate>

    <FooterTemplate>
    </table>
    </FooterTemplate>

    </asp:Repeater>
    </form>

    </body>
    </html>

    演示實(shí)例 ?

    使用 <SeparatorTemplate>

    <SeparatorTemplate> 元素用于描述每個(gè)記錄之間的分隔符。在下面的實(shí)例中,每個(gè)表格行之間插入了一條水平線:

    實(shí)例

    <%@ Import Namespace="System.Data" %>

    <script runat="server">
    sub Page_Load
    if Not Page.IsPostBack then
    dim mycdcatalog=New DataSet
    mycdcatalog.ReadXml(MapPath("cdcatalog.xml"))
    cdcatalog.DataSource=mycdcatalog
    cdcatalog.DataBind()
    end if
    end sub
    </script>

    <html>
    <body>

    <form runat="server">
    <asp:Repeater id="cdcatalog" runat="server">

    <HeaderTemplate>
    <table border="0" width="100%">
    <tr>
    <th>Title</th>
    <th>Artist</th>
    <th>Country</th>
    <th>Company</th>
    <th>Price</th>
    <th>Year</th>
    </tr>
    </HeaderTemplate>

    <ItemTemplate>
    <tr>
    <td><%#Container.DataItem("title")%></td>
    <td><%#Container.DataItem("artist")%></td>
    <td><%#Container.DataItem("country")%></td>
    <td><%#Container.DataItem("company")%></td>
    <td><%#Container.DataItem("price")%></td>
    <td><%#Container.DataItem("year")%></td>
    </tr>
    </ItemTemplate>

    <SeparatorTemplate>
    <tr>
    <td colspan="6"><hr /></td>
    </tr>
    </SeparatorTemplate>

    <FooterTemplate>
    </table>
    </FooterTemplate>

    </asp:Repeater>
    </form>

    </body>
    </html>

    演示實(shí)例 ?

    關(guān)閉
    程序員人生
    主站蜘蛛池模板: 欧美三级午夜伦理片 | 成人亚洲欧美综合 | 国产精品久久久久久久午夜片 | 国产v综合v亚洲欧美大另类 | 亚洲欧美国产一区二区三区 | 色综合天天综合网国产成人 | 亚洲欧美日韩另类 | 午夜dj高清免费观看视频www | 手机看片久久高清国产日韩 | 黄色网址免费在线 | 影音先锋色成人资源网站 | 国产大象视频一区二区 | 2021国产精品一区二区在线 | 亚洲精品视频免费 | 亚洲精品国产精品一区二区 | 国产日韩精品欧美一区喷 | 一区二区三区在线 | 日本 | 最近中文字幕经典版在线 | 2020久久精品国产免费 | 亚欧精品一区二区三区四区 | 天堂网在线网站成人午夜网站 | 日本精品一区二区在线播放 | 狠狠干天天爱 | 我要看日本黄色片 | 国产高清免费不卡观看 | 国产精品ⅴ视频免费观看 | 日韩国产精品99久久久久久 | 日韩欧美亚洲综合 | 久久国产精品免费一区二区三区 | 国产成人精品曰本亚洲 | 伊人免费视频网 | 亚洲色图欧美在线 | 国产日韩欧美一区二区三区视频 | h视频网站在线观看 | 国产免费一级高清淫曰本片 | 最新日韩欧美不卡一二三区 | 国产91高跟丝袜 | 亚洲 欧美 在线观看 | 亚洲欧美成人中文在线网站 | 欧美一级做 | 日韩一级在线观看 |