开发者

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

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"

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜