Repeater绑定List、Dictionary

2017/2/5 11:17:35

Category 软件技术 Tag repeater,list,dictionary,泛型,数组

绑定List:

.cs:

List<CInfo> lst = new List<CInfo>();

rpt.DataSource = lst;

rpt.DataBind();


.aspx:

<%#((CInfo)Container.DataItem).ID%>

如绑定的是数组:<%# GetDataItem()%>


绑定Dictionary:

.cs:

Dictionary<string, int> lst1 = new Dictionary<string, int>();

//添加内容

//...


//绑定

rpt.DataSource = lst1;

rpt.DataBind();


aspx:

...

<%#((System.Collections.Generic.KeyValuePair<string, int>)Container.DataItem).Key%>

<%#((System.Collections.Generic.KeyValuePair<string, int>)Container.DataItem).Value%>