C# 如何绑定列表<;字符串>;进入WebForms中的ListView

C# 如何绑定列表<;字符串>;进入WebForms中的ListView,c#,asp.net,list,listview,C#,Asp.net,List,Listview,我有一个列表集合,我想将它绑定到我的列表视图 下面是我的列表视图的标记: <asp:ListView ID="lvList" runat="server"> <LayoutTemplate> <div id="Div1" runat="server"> <div ID="itemPlaceholder" runat="server"&g

我有一个
列表
集合,我想将它绑定到我的
列表视图

下面是我的
列表视图的标记:

<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>

没有返回任何数据。
在我的代码背后:

protected void Page_Load(object sender, EventArgs e)
{         
    List<string> theList = new List<string>();
    //populate members of list
    lvList.DataSource = theList;
    lvList.DataBind();
}
受保护的无效页面加载(对象发送方,事件参数e)
{         
列表列表=新列表();
//填充列表的成员
lvList.DataSource=列表;
lvList.DataBind();
}
错误消息:

System.Web.HttpException未由用户代码处理
Message=“DataBinding:'System.String'不包含带有 “名称‘列表’。”

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

使用



EVAL用于单个键值,数据绑定控件从开始到结束遍历集合,并逐个放置在放置EVAL语句的位置

这个链接中的答案可以提供更好的想法。

希望这会有所帮助

<asp:Label ID="ProductNameLabel" runat="server" Text='<%# Container.DataItem %>'/>
protected void Test(object obj)
{
    return obj.ToString();
}
 <asp:Label ID="ProductNameLabel" runat="server" Text='<%# Test(Container.DataItem) %>