Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/280.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 从运行时确定的数字生成ListView项,而不是从数据源生成_C#_Asp.net_Listview_Web Applications_Webforms - Fatal编程技术网

C# 从运行时确定的数字生成ListView项,而不是从数据源生成

C# 从运行时确定的数字生成ListView项,而不是从数据源生成,c#,asp.net,listview,web-applications,webforms,C#,Asp.net,Listview,Web Applications,Webforms,我试图让列表视图控件根据用户单击“添加”按钮的次数,显示用户喜欢的任意多个表单。基本上,我不想将列表视图绑定到数据源,而是以编程方式添加项目模板,1、5、13或我喜欢的次数。出于测试目的,假设我想向列表视图添加13个表单。有没有办法做到这一点?顺便说一句,我正在使用System.Web.UI.WebControls.ListView。ListView: <asp:ListView ID="ListView1" runat="server" > <ItemTemplate

我试图让
列表视图
控件根据用户单击“
添加
”按钮的次数,显示用户喜欢的任意多个表单。基本上,我不想将
列表视图
绑定到
数据源
,而是以编程方式添加
项目模板
,1、5、13或我喜欢的次数。出于测试目的,假设我想向
列表视图添加13个表单。有没有办法做到这一点?顺便说一句,我正在使用
System.Web.UI.WebControls.ListView

ListView:

<asp:ListView ID="ListView1" runat="server" >
    <ItemTemplate><br /><%# Eval("Value") %></ItemTemplate>
</asp:ListView>
您还可以使用对象列表而不是DataTable

    var dt = new DataTable();
    dt.Columns.Add("Value", typeof(string));
    var row = dt.NewRow();
    row["Value"] = "first record";
    dt.Rows.Add(row);
    row = dt.NewRow();
    row["Value"] = "second record";
    dt.Rows.Add(row);
    //other records if needed
    ListView1.DataSource = dt;
    ListView1.DataBind();