add new row in gridview after binding C#, ASP.net

前端 未结 5 1070
攒了一身酷
攒了一身酷 2020-12-09 04:26

\"enter

I want to add a new blank row to the gridview after binding as seen in the pic

5条回答
  •  慢半拍i
    慢半拍i (楼主)
    2020-12-09 04:46

    protected void TableGrid_RowDataBound(object sender, GridViewRowEventArgs e)
    {
       if (e.Row.RowIndex == -1 && e.Row.RowType == DataControlRowType.Header)
       {
          GridViewRow gvRow = new GridViewRow(0, 0, DataControlRowType.DataRow,DataControlRowState.Insert);
          for (int i = 0; i < e.Row.Cells.Count; i++)
          {
             TableCell tCell = new TableCell();
             tCell.Text = " ";
             gvRow.Cells.Add(tCell);
             Table tbl = e.Row.Parent as Table;
             tbl.Rows.Add(gvRow);
          }
       }
    }
    

提交回复
热议问题