JulZc JulZc - 2 months ago 21
ASP.NET (C#) Question

Binding Generic List in Asp.Net

C#

List<Rating> ratingList = new List<Rating>();

public class Rating
{
public string CustomerName;
}

RptCustomerRating.DataSource = ratingList;
RptCustomerRating.DataBind();


In the debugmode the List is filled. But in the itemtemplate Eval doesn't work at all...

Aspx File Version 1

<asp:Repeater ID="RptCustomerRating" runat="server">
<ItemTemplate>
<div class="row">
<div class="col-md-12">
<h2><%#Eval("CustomerName") %></h2>
</div>
</div>
</ItemTemplate>
</asp:Repeater>


My Error:

System.Web.HttpException: DataBinding: CRating+Rating contains no property named CustomerName.

Aspx File Version 2

<asp:Repeater ID="RptCustomerRating" runat="server">
<ItemTemplate>
<asp:Repeater ID="inner" runat="server">
<ItemTemplate>
<div class="row">
<div class="col-md-12">
<h2><%#Eval("CustomerName") %></h2>
</div>
</div>
</ItemTemplate>
</asp:Repeater>
</ItemTemplate>
</asp:Repeater>


This is what i found on stackoverflow. Someone recommend to solve the problem with nested repeaters. Well Visual Studio can't find a error, but in this case nothing happend. The html part is empty.

Answer

You need to get and set the property CustomerName

public class Rating
{
    public string CustomerName {get; set;}
}