向gridview添加10个空行

时间:2014-05-30 11:42:12

标签: 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">
                    <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个空行?

2 个答案:

答案 0 :(得分:2)

you can try this 

 string[] str = new string[10]; 
 List lstStr = str.ToList<string>();
 gv_Others.DataSource = lstStr ;
 gv_Others.DataBind();

答案 1 :(得分:1)

var list = new List<string>();

for (int i = 0; i < 10; i++)
{
    list.Add(string.Empty);
}
gv_Others.DataSource = list;
gv_Others.DataBind();

这是我能想到的最快最肮脏的方式,我会写这样的东西吗?不。但是我确定你有理由,如果你在问题中写下你想要达到的目标会更好,那么我们可以帮助更多,你的问题也不会被标记下来。

相关问题