国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 編程 > .NET > 正文

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

2024-07-10 13:16:40
字體:
供稿:網(wǎng)友
.aspx頁面代碼

復(fù)制代碼 代碼如下:


<asp:Repeater runat="server">
<ItemTemplate>
<%# ((KeyValuePair<int, List<User>>)Container.DataItem).Key %> <br />
<asp:Repeater 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ù)源的,尤其要注意對象引起的問題
發(fā)表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發(fā)表
主站蜘蛛池模板: 英吉沙县| 洪泽县| 绥化市| 兴义市| 凤阳县| 锡林浩特市| 玛沁县| 屯留县| 新泰市| 长顺县| 河北区| 仪陇县| 思茅市| 勐海县| 湖南省| 天水市| 拉萨市| 岳池县| 卢湾区| 正宁县| 香格里拉县| 乐安县| 延庆县| 博兴县| 涪陵区| 奎屯市| 砀山县| 利辛县| 阳新县| 济源市| 济南市| 布拖县| 新郑市| 岱山县| 蒙山县| 乌拉特后旗| 达日县| 大城县| 阳曲县| 体育| 内黄县|