Repeater binding dictionary data source code and error resolution _ Practical skills

Source: Internet
Author: User
. 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

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.