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

前端 未结 5 1058
攒了一身酷
攒了一身酷 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条回答
  •  野趣味
    野趣味 (楼主)
    2020-12-09 04:59

    you can try the following code

    protected void Button1_Click(object sender, EventArgs e)
       {
           DataTable dt = new DataTable();
    
           if (dt.Columns.Count == 0)
           {
               dt.Columns.Add("PayScale", typeof(string));
               dt.Columns.Add("IncrementAmt", typeof(string));
               dt.Columns.Add("Period", typeof(string));
           }
    
           DataRow NewRow = dt.NewRow();
           NewRow[0] = TextBox1.Text;
           NewRow[1] = TextBox2.Text;
           dt.Rows.Add(NewRow); 
           GridView1.DataSource = dt;
           GridViewl.DataBind();
       }
    

    here payscale,incrementamt and period are database field name.

提交回复
热议问题