I have a List<string> collection that I would like to bind into my ListView.
Below is the markup for my 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>
in my CodeBehind:
protected void Page_Load(object sender, EventArgs e)
{
List<string> theList = new List<string>();
//populate members of list
lvList.DataSource = theList;
lvList.DataBind();
}
Error Message:
System.Web.HttpException was unhandled by user code
Message=”DataBinding: ‘System.String’ does not contain a property with
the name ‘theList’.”
I think I am doing things wrongly here, can someone advise me pls?
Use
'<%# Container.DataItem %>: