Binding a List<string> to a Listview in asp.net 3.5

Sash picture Sash · Jul 12, 2010 · Viewed 9.7k times · Source

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.

Answer

onof picture onof · Jul 12, 2010

Don't use Eval. Bind it directly:

<%# Container.DataItem %>