. aspx page code
Copy Code code as follows:
<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>
</ItemTemplate>
</asp:Repeater>
. Aspx.cs Post Code
Copy Code code as follows:
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;}
}
If you report the following error:
Repeater is using an invalid data source. Does a valid data source have to implement IListSource or IEnumerable?
is due to a data source type problem, such as a DataTable dataset Xml Arrry Collection
A type such as a String int object cannot be used directly as its data source, especially if the object is causing the problem