单击下面的链接按钮时,我想在绑定(bind)后向 gridview 添加一个新的空白行,如图所示。如果其中输入了任何数据,则 gridview 内的文本框应保持不变。我只想添加一行。
最佳答案
你可以试试下面的代码
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是数据库字段名。
关于c# - 绑定(bind) C#、ASP.net 后在 gridview 中添加新行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19485909/