. Aspx page code
Copy codeThe Code is 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>
<Hr/>
</ItemTemplate>
</Asp: Repeater>
. Aspx. cs post code
Copy codeThe Code is 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 the following error is reported::
The repeater uses an invalid data source. Valid data sources must be IListSource or IEnumerable?
The data source type is incorrect, for example, DataTable DataSet Xml Arrry set.
A type such as a String int object cannot be directly used as its data source. Pay special attention to the problems caused by objects.