How do I bind a List to a in ASP.NET 3.5
<asp:ListView ID="lvDiagnosisCodes" runat="server">
<LayoutTemplate>
<ul>
<asp:PlaceHolder ID="itemPlaceholder" runat="server"></asp:PlaceHolder>
</ul>
</LayoutTemplate>
<ItemTemplate>
<li>
<%# Eval("Name") %>
</li>
</ItemTemplate>
</asp:ListView>
I am not too sure what do use in the Eval part. Since this is a generic List of string , there is no column name.
Thanks in advance.
Don't use Eval. Bind it directly:
<%# Container.DataItem %>
All you have to do is create an anonymous object and set it to the Datasource property of your Listview.
So if you have a list or an array of strings, do the following:
Dim myListOfStuff() As String = Manager.FetchMyStuff()
Me.lvDiagnosisCodes.DataSource = (From s In myListOfStuff Select New With {.Name = s}).ToArray
Me.lvDiagnosisCodes.DataSource.DataBind()
This way, you can use <%# Eval("Name") %>
in the front end and bind to a "property"
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With