当前位置: 移动技术网 > IT编程>开发语言>.net > Repeater绑定dictionary数据源代码及报错解决

Repeater绑定dictionary数据源代码及报错解决

2017年12月12日  | 移动技术网IT编程  | 我要评论

幽灵鬼屋女主角,高清电影下载 1080p,手机铃声下载 mp3

.aspx页面代码
复制代码 代码如下:

<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 使用的是无效数据源。有效数据源必须实现 ilistsource 或 ienumerable?
是因为数据源类型问题,比如 datatable dataset xml arrry 集合
像 string int 对象 这样的类型是不能直接作为它的数据源的,尤其要注意对象引起的问题

如对本文有疑问,请在下面进行留言讨论,广大热心网友会与你互动!! 点击进行留言回复

相关文章:

验证码:
移动技术网