在gridview上添加新行 [英] adding new row on gridview
本文介绍了在gridview上添加新行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我已经绑定了数据库中的数据并使用此代码在girdview上显示。
现在我想在gridview上添加一个按钮,用于在gridview上添加新行。
请帮我在gridview上添加新行。
I have bind the data from database and show on girdview using this code.
Now I want to add a button on gridview for adding new row on gridview.
Please help me to add new row on gridview.
if (!Page.IsPostBack)
{
binddata();
}
}
private void binddata()
{
string connstring = @"Data Source=LENOVO-41B3F2CE\SQLEXPRESS;Initial Catalog=IMS;Integrated Security=True;Pooling=False";
string query = "SELECT * FROM ['ISB VAS Nodes$']";
SqlDataAdapter da = new SqlDataAdapter(query, connstring);
DataTable dt = new DataTable();
da.Fill(dt);
GridView1.DataSource = dt;
GridView1.DataBind();
}
推荐答案
'];
SqlDataAdapter da = new SqlDataAdapter(query,connstring);
DataTable dt = new DataTable();
da.Fill( dt);
GridView1.DataSource = dt;
GridView1.DataBind();
}
']"; SqlDataAdapter da = new SqlDataAdapter(query, connstring); DataTable dt = new DataTable(); da.Fill(dt); GridView1.DataSource = dt; GridView1.DataBind(); }
hi,
您可以通过两种方式完成此任务:
1.您可以在数据库中插入数据然后绑定Gridview的新数据
2.或者将Gridview数据放入数据表中并将数据插入数据表中,然后从中绑定新的
数据数据表到Gridview。
You can do this in two ways:
1. Either you insert the data in database then bind the new data to Gridview
2. Or else take Gridview data in a datatable and insert data into datatable and then bind new
data from the datatable to Gridview.
将数据表复制到会话中,并在单击按钮时添加一行到datatable并使用新的datatabl绑定gridview; e并将数据表复制回会话。
Hi,
copy the datatable to the session, and on click of the button add a row to datatable and bind the gridview with the new datatabl;e and copy the datatable back to session.
private void binddata()
{
string connstring = @"Data Source=LENOVO-41B3F2CE\SQLEXPRESS;Initial Catalog=IMS;Integrated Security=True;Pooling=False";
string query = "SELECT * FROM ['ISB VAS Nodes
这篇关于在gridview上添加新行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文