我有一个 List<string>
我想绑定(bind)到我的 ListView
中的集合.
下面是我的 ListView
的标记:
<asp:ListView ID="lvList" runat="server">
<LayoutTemplate>
<div id="Div1" runat="server">
<div ID="itemPlaceholder" runat="server">
</div>
</div>
</LayoutTemplate>
<EmptyDataTemplate>
<div id="Div2" runat="server">
<div ID="itemPlaceholder" runat="server">
No data was returned.
</div>
</div>
</EmptyDataTemplate>
<ItemTemplate>
<asp:Label ID="ProductNameLabel" runat="server" Text='<%# Eval ("theList") %>'/>
</ItemTemplate>
</asp:ListView>
在我的代码隐藏中:
protected void Page_Load(object sender, EventArgs e)
{
List<string> theList = new List<string>();
//populate members of list
lvList.DataSource = theList;
lvList.DataBind();
}
错误信息:
System.Web.HttpException was unhandled by user code
Message="DataBinding: 'System.String' does not contain a property with the name 'theList'."
我觉得我在这里做错了,有人可以给我建议吗?
最佳答案
使用 '<%# Container.DataItem %>
:
<asp:Label ID="ProductNameLabel" runat="server" Text='<%# Container.DataItem %>'/>
关于c# - 如何将 List<string> 绑定(bind)到 WebForms 中的 ListView,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10185992/