Repeater绑定dictionary数据源代码及报错解决
来源:互联网 发布:ubuntu 文件夹root权限 编辑:程序博客网 时间:2024/06/05 10:55
<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 对象 这样的类型是不能直接作为它的数据源的,尤其要注意对象引起的问题
http://www.thinksaas.cn/topics/0/58/58194.html
<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 对象 这样的类型是不能直接作为它的数据源的,尤其要注意对象引起的问题
http://www.thinksaas.cn/topics/0/58/58194.html
0 0
- Repeater绑定dictionary数据源代码及报错解决
- Repeater绑定dictionary数据源
- Repeater控件自定义数据源代码绑定实例
- Repeater绑定Dictionary
- asp:Repeater绑定数据源
- Repeater绑定IList<T>数据源
- COMBOBOX绑定DICTIONARY做为数据源
- COMBOBOX绑定DICTIONARY做为数据源
- 水晶报表绑定数据源报错
- Repeater绑定Xml数据源或文件
- Repeater绑定Xml数据源或文件
- Repeater中的下拉列表DropDownList绑定数据源
- Repeater绑定数据页面代码
- Repeater控件绑定及分页
- jndi连接数据源报错解决
- list<R>和 Dictionary<R>绑定数据源的实例
- WPF的ComboBox数据绑定,使用Dictionary作为数据源
- WPF-获取Combobox已绑定的数据源并转成Dictionary
- MPI学习之路(一)
- yii2学习笔记——自定义报错机制
- Android数据存储-->SharedPreferences
- Java基础--IO流
- Angular2-primeNG 文件上传模块FileUpload
- Repeater绑定dictionary数据源代码及报错解决
- LeetCode No.9 Palindrome Number
- 校门外的树
- 09-排序2 Insert or Merge (25分)
- android自定义输入法判断是否在输入状态的问题
- CXF
- Linux 文件权限与目录配置(有机会可以挑战FHS英文官方文档来加深你对目录了解)
- JianZhiOffer_p33_把数组排成最小的数
- 中国最著名的黑客排行榜