栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > asp

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

asp 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

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

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


<%# ((KeyValuePair>)Container.DataItem).Key %>

>)Container.DataItem).Value %>'>

<%# (Container.DataItem as User).Id %>
<%# (Container.DataItem as User).Name %>







.aspx.cs后置代码
复制代码 代码如下:
public partial class Temp : System.Web.UI.Page
{
Dictionary> dict = new Dictionary>();
protected void Page_Load(object sender, EventArgs e)
{
dict.Add(1, new List
{
new User{Id = 1, Name = "aa"}
,new User{Id = 2, Name = "bb"}
});
dict.Add(2, new List
{
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 对象 这样的类型是不能直接作为它的数据源的,尤其要注意对象引起的问题
转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/57783.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号