欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

Repeater綁定dictionary數(shù)據(jù)源代碼及報錯解決

 更新時間:2013年04月18日 17:22:36   作者:  
為大家講解下Repeater綁定dictionary數(shù)據(jù)源以及報錯處理的方法,感興趣的朋友可以參考下哈,希望對你有所幫助
.aspx頁面代碼
復(fù)制代碼 代碼如下:

<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后置代碼
復(fù)制代碼 代碼如下:

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ù)源的,尤其要注意對象引起的問題

相關(guān)文章

最新評論