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

首頁 > 編程 > .NET > 正文

Repeater綁定dictionary數據源代碼及報錯解決

2024-07-10 12:45:48
字體:
來源:轉載
供稿:網友
.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 對象 這樣的類型是不能直接作為它的數據源的,尤其要注意對象引起的問題
發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 烟台市| 泸溪县| 阿巴嘎旗| 吴旗县| 东光县| 延寿县| 陇西县| 香河县| 论坛| 合江县| 遂溪县| 云和县| 吕梁市| 德昌县| 浙江省| 灵川县| 鄂托克旗| 东兴市| 大港区| 增城市| 辉县市| 大足县| 南华县| 石泉县| 贵州省| 龙口市| 河津市| 哈巴河县| 商丘市| 马山县| 久治县| 阜新| 阳春市| 平顶山市| 绥滨县| 彭山县| 兴仁县| 溆浦县| 寻乌县| 南平市| 北京市|