绑定 C#、ASP.net 后在 gridview 中添加新行

编程入门 行业动态 更新时间:2024-10-27 22:25:12
本文介绍了绑定 C#、ASP 后在 gridview 中添加新行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

限时送ChatGPT账号..

当单击下面的链接按钮时,我想在绑定后向 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 后在 gridview 中添加新行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

更多推荐

[db:关键词]

本文发布于:2023-04-01 10:58:56,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/828318.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:绑定   ASP   gridview   net

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!