如何将List <string>绑定到WebForms中的ListView中

rof*_*s91 5 c# asp.net listview list

我有一个List<string>集合,我想绑定到我的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>
Run Code Online (Sandbox Code Playgroud)

在我的CodeBehind中:

protected void Page_Load(object sender, EventArgs e)
{         
    List<string> theList = new List<string>();
    //populate members of list
    lvList.DataSource = theList;
    lvList.DataBind();
}
Run Code Online (Sandbox Code Playgroud)

错误信息:

System.Web.HttpException
未被用户代码处理Message ="DataBinding:'System.String'不包含名为'theList'的属性."

我想我在这里做错了,有人可以告诉我吗?

ion*_*den 9

用途'<%# Container.DataItem %>:

<asp:Label ID="ProductNameLabel" runat="server" Text='<%# Container.DataItem %>'/>
Run Code Online (Sandbox Code Playgroud)