Source code bound to dictionary data by Repeater and troubleshooting

Source: Internet
Author: User

. 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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.