最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

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ù)源必須實(shí)現(xiàn) IListSource 或 IEnumerable?
是因?yàn)閿?shù)據(jù)源類型問題,比如 DataTable DataSet Xml Arrry 集合
像 String int 對象 這樣的類型是不能直接作為它的數(shù)據(jù)源的,尤其要注意對象引起的問題

相關(guān)文章

最新評論

盐津县| 铜山县| 望奎县| 山东省| 南召县| 贵港市| 鸡泽县| 遂平县| 泗洪县| 安岳县| 丰台区| 乳山市| 远安县| 赣州市| 平乐县| 吴忠市| 阳信县| 苏州市| 白城市| 保定市| 兴山县| 遂昌县| 永定县| 山阳县| 镇原县| 陆丰市| 涞水县| 修武县| 新竹市| 芜湖市| 临汾市| 黄浦区| 讷河市| 奉节县| 尚志市| 布拖县| 嘉峪关市| 靖江市| 苍山县| 嵊州市| 阜康市|