C# 向gridview添加10个空行
我需要在默认情况下Gridview必须有10个空行,其中只有一列应该有Textbox 这是我的gridview脚本C# 向gridview添加10个空行,c#,jquery,asp.net,gridview,C#,Jquery,Asp.net,Gridview,我需要在默认情况下Gridview必须有10个空行,其中只有一列应该有Textbox 这是我的gridview脚本 <asp:GridView ID="gv_Others" runat="server" AutoGenerateColumns="false" onrowdatabound="gv_Others_RowDataBound" onrowcreated="gv_Others_RowCreated"&
<asp:GridView ID="gv_Others" runat="server" AutoGenerateColumns="false"
onrowdatabound="gv_Others_RowDataBound"
onrowcreated="gv_Others_RowCreated">
<Columns>
<asp:TemplateField ItemStyle-Width="40px">
<ItemStyle HorizontalAlign="Center" VerticalAlign="Middle" />
<ItemTemplate>
<asp:TextBox ID="txtemp" runat="server"></asp:TextBox>
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
是否可以在gridview中默认创建10个空行?var list=new list();
var list = new List<string>();
for (int i = 0; i < 10; i++)
{
list.Add(string.Empty);
}
gv_Others.DataSource = list;
gv_Others.DataBind();
对于(int i=0;i<10;i++)
{
list.Add(string.Empty);
}
gv_Others.DataSource=列表;
gv_Others.DataBind();
这是我能想到的最快最脏的方式,我会写这样的东西吗?没有。但我相信你有你的理由,如果你在问题中写下你想要达到的目标,我们会帮助你更多,你的问题也不会被记下来。你可以试试这个
you can try this
string[] str = new string[10];
List lstStr = str.ToList<string>();
gv_Others.DataSource = lstStr ;
gv_Others.DataBind();
字符串[]str=新字符串[10];
List lstStr=str.ToList();
gv_Others.DataSource=lstStr;
gv_Others.DataBind();
如果您知道如何将数据添加到girdview中,那么您可以传入一些空字符串。我之所以需要这些字符串,是因为我想插入多个值,这样现在我可以通过循环Gridview行轻松找到所有值,然后可以将值插入数据库表。另一个。
var list=new list(10);list.AddRange(Enumerable.Repeat(String.Empty,10))代码>