绑定 C#、ASP.net 后在 gridview 中添加新行 [英] add new row in gridview after binding C#, ASP.net

查看:24
本文介绍了绑定 C#、ASP.net 后在 gridview 中添加新行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当单击下面的链接按钮时,我想在绑定后向 gridview 添加一个新的空白行,如图所示.如果在其中输入了任何数据,则 gridview 内的文本框应保持不变.只想添加一行.请帮我.提前致谢.

I want to add a new blank row to the gridview after binding as seen in the picture when clicking the link button below. The textboxes inside the gridview should remain the same if there is any data entered in it. just want to add one row. please help me. Thanks in advance.

推荐答案

可以试试下面的代码

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();
   }

这里的payscale、incrementamt 和 period 是数据库字段名.

here payscale,incrementamt and period are database field name.

这篇关于绑定 C#、ASP.net 后在 gridview 中添加新行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆