C#
List<Rating> ratingList = new List<Rating>();
public class Rating
{
public string CustomerName;
}
RptCustomerRating.DataSource = ratingList;
RptCustomerRating.DataBind();
在调试模式中填充List。但是在项目模板中,Eval根本不起作用......
Aspx文件版本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>
我的错误:
System.Web.HttpException:DataBinding:CRating + Rating不包含名为CustomerName的属性。
Aspx文件版本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>
这是我在stackoverflow上找到的。有人建议使用嵌套转发器来解决问题。 Visual Studio无法找到错误,但在这种情况下没有任何事情发生。 html部分是空的。
答案 0 :(得分:2)
您需要get
和set
财产CustomerName
public class Rating
{
public string CustomerName {get; set;}
}
答案 1 :(得分:0)
您使用的是Field,而不是Property。这就是你遇到这样的错误的原因。
public class Rating
{
public string CustomerName; // <= this is a field
}
public class Rating
{
public string CustomerName { get; set;} // <= this is a property
}