您好,登錄后才能下訂單哦!
今天小編就為大家?guī)?lái)一篇Repeater中DataSource和數(shù)據(jù)顯示總結(jié)的文章。小編覺(jué)得挺不錯(cuò)的,為此分享給大家做個(gè)參考。一起跟隨小編過(guò)來(lái)看看吧。
- #region 定義List<string>的數(shù)據(jù)源類型
- List<string> testDS1 = new List<string>() { "1", "2" };//初始化數(shù)據(jù)
- this.Repeater1.DataSource = testDS1;//指定數(shù)據(jù)源
- this.Repeater1.DataBind();//綁定數(shù)據(jù)
- #endregion
- #region 定義List<person>的數(shù)據(jù)源類型
- List<person> testDS2 = new List<person>() { new person(1, "person1"), new person(2, "person2") };//初始化數(shù)據(jù)
- this.Repeater2.DataSource = testDS2;//指定數(shù)據(jù)源
- this.Repeater2.DataBind();//綁定數(shù)據(jù)
- #endregion
- #region 定義Dictionary<string,string>的數(shù)據(jù)源類型
- Dictionary<string, string> testDS3 = new Dictionary<string, string>() { { "1", "value1" }, { "2", "value2" } };//初始化數(shù)據(jù)
- this.Repeater3.DataSource = testDS3;//指定數(shù)據(jù)源
- this.Repeater3.DataBind();//綁定數(shù)據(jù)
- #endregion
- <div>
- <a>第一個(gè)repeater顯示的數(shù)據(jù):</a>
- <asp:Repeater ID="Repeater1" runat="server">
- <HeaderTemplate>
- <table>
- <th>
- 顯示
- </th>
- </HeaderTemplate>
- <ItemTemplate>
- <tr>
- <td>
- <%#Container.DataItem %>
- </td>
- </tr>
- </ItemTemplate>
- <FooterTemplate>
- </table>
- </FooterTemplate>
- </asp:Repeater>
- </div>
- <div >
- <a>第二個(gè)repeater顯示的數(shù)據(jù):</a>
- <asp:Repeater ID="Repeater2" runat="server">
- <HeaderTemplate>
- <table>
- <th>
- Age
- </th>
- <th>
- Name
- </th>
- </HeaderTemplate>
- <ItemTemplate>
- <tr>
- <td>
- <%#DataBinder.Eval(Container.DataItem,"Age") %>
- </td>
- <td>
- <%#DataBinder.Eval(Container.DataItem,"Name") %>
- </td>
- </tr>
- </ItemTemplate>
- <FooterTemplate>
- </table>
- </FooterTemplate>
- </asp:Repeater>
- </div>
- <div>
- <a>第三個(gè)repeater顯示的數(shù)據(jù):</a>
- <asp:Repeater ID="Repeater3" runat="server">
- <HeaderTemplate>
- <table>
- <th>
- Key
- </th>
- <th>
- Value
- </th>
- </HeaderTemplate>
- <ItemTemplate>
- <tr>
- <td>
- <%#Eval("key") %>
- </td>
- <td>
- <%#Eval("value") %>
- </td>
- </tr>
- </ItemTemplate>
- <FooterTemplate>
- </table>
- </FooterTemplate>
- </asp:Repeater>
- </div>
Container則是ASP.NET頁(yè)面編譯器在數(shù)據(jù)綁定事件處理程序內(nèi)部聲明的局部變量,其類型是可以進(jìn)行數(shù)據(jù)綁定的控件的數(shù)據(jù)容器類型(如在Repeater內(nèi)部的數(shù)據(jù)綁定容器叫RepeaterItem),在這些容器類中基本都有DataItem屬性,因此你可以寫Container.DataItem,這個(gè)屬性返回的是你正在被綁定的數(shù)據(jù)源中的那個(gè)數(shù)據(jù)項(xiàng)。如果你的數(shù)據(jù)源是DataTable,則這個(gè)數(shù)據(jù)項(xiàng)的類型實(shí)際是DataRowView。
免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如果涉及侵權(quán)請(qǐng)聯(lián)系站長(zhǎng)郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。