Click here to Skip to main content
15,885,985 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
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
Posted

1 solution

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:
C#
DataTable dt = new DataTable();
dt.Columns.Add("Column1_Name", typeof(string));
dt.Columns.Add("Column2_Name", typeof(string));
GridView1.DataSource = dt;
GridView1.DataBind();


and in the OnClick event of your "Add" button :
C#
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


then you can loop the DataTable dt to check for duplication
 
Share this answer
 
Comments
ankur789 31-Jul-13 23:48pm    
i put where in my code
DataTable dt = new DataTable();
dt.Columns.Add("Column1_Name", typeof(string));
dt.Columns.Add("Column2_Name", typeof(string));
GridView1.DataSource = dt;
GridView1.DataBind();
Hend Riad 1-Aug-13 0:00am    
you can put it in the page load event
ankur789 1-Aug-13 0:42am    
not working
Hend Riad 1-Aug-13 6:00am    
what is the problem? it works with me

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900