【问题标题】:add row at the top of the gridview in c#在c#中的gridview顶部添加行
【发布时间】:2017-02-17 13:47:31
【问题描述】:

如何在 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>

图片如下: 我想在项目模板字段的网格顶部添加行..

我想在网格的顶部,而不是第一行的最后一行,我想添加行..有什么建议吗??

【问题讨论】:

  • 您可以重新格式化您发布的内容以使其可读吗?到目前为止,您编写了哪些代码来解决此问题?
  • 到目前为止,您编写了哪些代码来添加新行?

标签: asp.net gridview webforms


【解决方案1】:

这个例子展示了如何在 dgv 的顶部插入新行(到绑定的 dgv,dataSource 是一个 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);
}

【讨论】:

  • 先生,我的问题是我想要在 gridview 的顶部,即在 gridview 的第一行添加带有添加新按钮的行...
猜你喜欢
  • 2014-07-05
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多