2017-02-17 111 views
0

如何在Gridview顶部添加新行? 下面是代码:在c的gridview顶部添加一行#

<FooterTemplate> 
    <asp:Button ID="btnsave" runat="server" Text="Add New" 
     class="btn icon-btn btn-success btn-sm" 
     OnClientClick="return GetGridFooterRowvalues()" 
     OnClick="btnsave_Click" /> 
</FooterTemplate> 

这里是图像: enter image description here 我希望在网格顶部的项目模板字段中添加一行..

我想在网即顶部而不是在第一行的最后一行,我想添加行..任何建议?

+0

你能重新格式化您发布,使其可读?你到目前为止写了哪些代码来解决这个问题? –

+0

+0

至此您添加了哪些代码来添加新行? –

回答

0

这个例子显示了如何在DGV的顶部插入新行(到绑定DGV,数据源是一个DataTable):

DataTable table; 
public Form1() 
{ 
    InitializeComponent(); 
    //initializing new dataTable and its columns 
    //and setting the dataSource property to dgv: 
    table = new DataTable("myTable"); 
    table.Columns.Add("column 1", typeof(int)); 
    table.Columns.Add("column 2", typeof(string)); 
    table.Rows.Add(1, "item 1"); 
    table.Rows.Add(2, "item 2"); 
    dataGridView1.DataSource = table; 
    dataGridView1.AllowUserToAddRows = false; 
} 

private void button1_Click(object sender, EventArgs e) 
{ 
    //How to insert new row at the top: 
    DataRow dr = table.NewRow(); 
    table.Rows.InsertAt(dr, 0); 
} 
+0

先生我的问题是我想要在gridview的顶部,即在gridview的顶部行添加新行按钮... –

+0

我已经添加一个图像..你可以参考 –