主頁(yè) > 知識(shí)庫(kù) > Repeater綁定dictionary數(shù)據(jù)源代碼及報(bào)錯(cuò)解決

Repeater綁定dictionary數(shù)據(jù)源代碼及報(bào)錯(cuò)解決

熱門標(biāo)簽:團(tuán)購(gòu)網(wǎng)站 Mysql連接數(shù)設(shè)置 Linux服務(wù)器 銀行業(yè)務(wù) 科大訊飛語(yǔ)音識(shí)別系統(tǒng) 電子圍欄 阿里云 服務(wù)器配置
.aspx頁(yè)面代碼
復(fù)制代碼 代碼如下:

asp:Repeater ID="Repeater1" runat="server">
ItemTemplate>
%# ((KeyValuePairint, ListUser>>)Container.DataItem).Key %> br />
asp:Repeater ID="Repeater2" runat="server" DataSource='%# ((KeyValuePairint, ListUser>>)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
{
Dictionaryint, ListUser>> dict = new Dictionaryint, ListUser>>();
protected void Page_Load(object sender, EventArgs e)
{
dict.Add(1, new ListUser>
{
new User{Id = 1, Name = "aa"}
,new User{Id = 2, Name = "bb"}
});
dict.Add(2, new ListUser>
{
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;}
}

如果報(bào)以下錯(cuò)誤:
repeater 使用的是無(wú)效數(shù)據(jù)源。有效數(shù)據(jù)源必須實(shí)現(xiàn) IListSource 或 IEnumerable?
是因?yàn)閿?shù)據(jù)源類型問(wèn)題,比如 DataTable DataSet Xml Arrry 集合
像 String int 對(duì)象 這樣的類型是不能直接作為它的數(shù)據(jù)源的,尤其要注意對(duì)象引起的問(wèn)題
您可能感興趣的文章:
  • Repeater事件OnItemCommand取得行內(nèi)控件的方法
  • Repeater控件與PagedDataSource結(jié)合實(shí)現(xiàn)分頁(yè)功能
  • Repeater控件實(shí)現(xiàn)編輯、更新、刪除等操作示例代碼
  • Repeater怎么實(shí)現(xiàn)多行間隔顯示分隔符
  • Repeater中嵌套R(shí)epeater的示例介紹
  • repeater做刪除前彈窗詢問(wèn)實(shí)例
  • 給Repeater控件里添加序號(hào)的5種才常見(jiàn)方法介紹
  • asp.net Repeater 數(shù)據(jù)綁定的具體實(shí)現(xiàn)(圖文詳解)
  • .net JS模擬Repeater控件的實(shí)現(xiàn)代碼
  • Repeater控件綁定的三種方式
  • 利用js的Node遍歷找到repeater的一個(gè)字段實(shí)例介紹
  • ASP.NET筆記之 Repeater的使用
  • asp.net Repeater分頁(yè)實(shí)例(PageDataSource的使用)
  • asp.net中使用repeater和PageDataSource搭配實(shí)現(xiàn)分頁(yè)代碼
  • Repeater里switch的使用方法
  • Repeater控件動(dòng)態(tài)變更列(Header,Item和Foot)信息(重構(gòu)cs)
  • Repeater的FooterTemplate顯示某列總計(jì)思路與代碼
  • 嵌套repeater示例分享

標(biāo)簽:棗莊 江蘇 衢州 衡水 廣元 萍鄉(xiāng) 蚌埠 大理

巨人網(wǎng)絡(luò)通訊聲明:本文標(biāo)題《Repeater綁定dictionary數(shù)據(jù)源代碼及報(bào)錯(cuò)解決》,本文關(guān)鍵詞  ;如發(fā)現(xiàn)本文內(nèi)容存在版權(quán)問(wèn)題,煩請(qǐng)?zhí)峁┫嚓P(guān)信息告之我們,我們將及時(shí)溝通與處理。本站內(nèi)容系統(tǒng)采集于網(wǎng)絡(luò),涉及言論、版權(quán)與本站無(wú)關(guān)。
  • 相關(guān)文章
  • 收縮
    • 微信客服
    • 微信二維碼
    • 電話咨詢

    • 400-1100-266