0

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.

JulZc
  • 3
  • 2

2 Answers2

2

You need to get and set the property CustomerName

public class Rating
{
    public string CustomerName {get; set;}
}
Mairaj Ahmad
  • 14,434
  • 2
  • 26
  • 40
0

You are using a Field, not Property. That's why you got such error.

public class Rating
{
    public string CustomerName; // <= this is a field
}

public class Rating
{
    public string CustomerName { get; set;} // <= this is a property
}

Difference between fields and properties

Community
  • 1
  • 1
tym32167
  • 4,741
  • 2
  • 28
  • 32