Repeater綁定dictionary數(shù)據(jù)源代碼及報錯解決
<asp:Repeater ID="Repeater1" runat="server">
<ItemTemplate>
<%# ((KeyValuePair<int, List<User>>)Container.DataItem).Key %> <br />
<asp:Repeater ID="Repeater2" runat="server" DataSource='<%# ((KeyValuePair<int, List<User>>)Container.DataItem).Value %>'>
<ItemTemplate>
<%# (Container.DataItem as User).Id %>
<%# (Container.DataItem as User).Name %>
</ItemTemplate>
</asp:Repeater>
<hr />
</ItemTemplate>
</asp:Repeater>
.aspx.cs后置代碼
public partial class Temp : System.Web.UI.Page
{
Dictionary<int, List<User>> dict = new Dictionary<int, List<User>>();
protected void Page_Load(object sender, EventArgs e)
{
dict.Add(1, new List<User>
{
new User{Id = 1, Name = "aa"}
,new User{Id = 2, Name = "bb"}
});
dict.Add(2, new List<User>
{
new User{Id = 3, Name = "cc"}
,new User{Id = 4, Name = "dd"}
});
Repeater1.DataSource = dict;
Repeater1.DataBind();
}
}
public class User
{
public int Id{get;set;}
public string Name{get;set;}
}
如果報以下錯誤:
repeater 使用的是無效數(shù)據(jù)源。有效數(shù)據(jù)源必須實現(xiàn) IListSource 或 IEnumerable?
是因為數(shù)據(jù)源類型問題,比如 DataTable DataSet Xml Arrry 集合
像 String int 對象 這樣的類型是不能直接作為它的數(shù)據(jù)源的,尤其要注意對象引起的問題
- Repeater事件OnItemCommand取得行內(nèi)控件的方法
- Repeater控件與PagedDataSource結(jié)合實現(xiàn)分頁功能
- Repeater控件實現(xiàn)編輯、更新、刪除等操作示例代碼
- Repeater怎么實現(xiàn)多行間隔顯示分隔符
- Repeater中嵌套Repeater的示例介紹
- repeater做刪除前彈窗詢問實例
- 給Repeater控件里添加序號的5種才常見方法介紹
- asp.net Repeater 數(shù)據(jù)綁定的具體實現(xiàn)(圖文詳解)
- .net JS模擬Repeater控件的實現(xiàn)代碼
- Repeater控件綁定的三種方式
- 利用js的Node遍歷找到repeater的一個字段實例介紹
- ASP.NET筆記之 Repeater的使用
- asp.net Repeater分頁實例(PageDataSource的使用)
- asp.net中使用repeater和PageDataSource搭配實現(xiàn)分頁代碼
- Repeater里switch的使用方法
- Repeater控件動態(tài)變更列(Header,Item和Foot)信息(重構(gòu)cs)
- Repeater的FooterTemplate顯示某列總計思路與代碼
- 嵌套repeater示例分享
相關(guān)文章
asp.net Page.EnableEventValidation 屬性驗證服務(wù)器控件的回發(fā)和回調(diào)事件出現(xiàn)的錯誤
Page.EnableEventValidation 屬性驗證服務(wù)器控件的回發(fā)和回調(diào)事件出現(xiàn)的錯誤前兩天用jQuery做了一個包含DropDownList聯(lián)動的頁面,數(shù)據(jù)通過Ajax請求得到的。2010-10-10ASP.NET泛型四之使用Lazy<T>實現(xiàn)延遲加載
這篇文章介紹了ASP.NET泛型使用Lazy<T>實現(xiàn)延遲加載的方法,文中通過示例代碼介紹的非常詳細。對大家的學(xué)習(xí)或工作具有一定的參考借鑒價值,需要的朋友可以參考下2022-08-08IIS實現(xiàn)反向代理時Cookie域的設(shè)置方法
這篇文章主要給大家介紹了關(guān)于IIS實現(xiàn)反向代理時Cookie域的設(shè)置方法,文中通過示例代碼介紹的非常詳細,對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧。2018-04-04asp.net 枚舉文件里面的數(shù)字綁定到DropDownList里面去
將枚舉文件里面的數(shù)字綁定到DropDownList里面去的實現(xiàn)方法,大家可以借鑒下。2009-07-07visual studio 2015+opencv2.4.13配置教程
這篇文章主要為大家詳細介紹了visual studio 2015+opencv2.4.13配置教程,具有一定的參考價值,感興趣的小伙伴們可以參考一下2017-11-11點擊圖片,AJAX刪除后臺圖片文件的實現(xiàn)代碼(asp.net)
點擊頁面上的圖片,用jQuery的AJAX來刪除后臺真實的文件。2010-11-11ASP.NET如何使用web服務(wù)的會話狀態(tài)
這篇文章主要介紹了ASP.NET如何使用web服務(wù)的會話狀態(tài),使用一個GridView中的會話對象來展示最近的計算結(jié)果,感興趣的小伙伴們可以參考一下2015-11-11.Net?Core?Aop之IResourceFilter的具體使用
本文主要介紹了.Net?Core?Aop之IResourceFilter的具體使用,文中通過示例代碼介紹的非常詳細,具有一定的參考價值,感興趣的小伙伴們可以參考一下2022-02-02