在网格视图中添加行,然后使用WEB FORM检查duplicay,保存数据库中的所有行

问题描述:

亲爱的先生,





我有一个带有两个文本框名称,地址,一个网格视图和两个按钮添加的Web表单行和保存。

先生使用窗口表单我可以通过点击添加行按钮添加行然后将其保存在数据库中。通过这个我可以在数据库中一次添加多行我也可以查看dupilicacy。

但是在网络表格中我该怎么办,我不明白请帮助我





谢谢

Dear Sir,


I have a web form with two text boxes name,address ,one grid view and two button add row and save.
Sir with the window form i am enable to add row through click on add row button and then save it in the database.By this i can add mutiple rows in one time in the database and i can also check the dupilicacy .
But in the web form how can i do it ,i donot understand please help me


Thank You

你可以让一个数据表有两列映射到两个文本框,向它添加两个文本框的值然后将其作为网格视图的数据源。如下所示:

You can have a data table have two columns mapped to the two text boxes, adding values of two text boxes to it and then make it the datasource of your grid view .. something like this:
DataTable dt = new DataTable();
dt.Columns.Add("Column1_Name", typeof(string));
dt.Columns.Add("Column2_Name", typeof(string));
GridView1.DataSource = dt;
GridView1.DataBind();





和添加按钮的OnClick事件:



and in the OnClick event of your "Add" button :

DataRow dr;
dr = dt.NewRow();
dr["Column1_Name"] = txtBox1.Text;
dr["Column2_Name"] = txtBox2.Text;
dt.Rows.Add(dr);
GridView.DataBind();

// you can add your code saving the record to database here





然后你可以循环DataTable dt来检查重复



then you can loop the DataTable dt to check for duplication