GridView CheckBox

Hii firenz..
If we check some particular checkboxes in the gridview ..the complete row must be stored in database..here the gridview contains the columns of different tables.
then..How can we store the row data of different column tables...

Thanx in advance...

Questions by shilu   answers by shilu

Showing Answers 1 - 1 of 1 Answers

You can't insert data in multiple table in one query but the other solution is below

first get data from gridview to a temp table (DataTable) as following:

{

 CheckBox cb;
  DataTable tb=new DataTable();
  tb.Columns.Add("eno", Type.GetType("System.Int32"));
  tb.Columns.Add("ename", Type.GetType("System.String"));
  tb.Columns.Add("eadd", Type.GetType("System.String"));
  tb.Columns.Add("esal", Type.GetType("System.Int32"));
  for (int i = 0; i < GridView1.Rows.Count; i++)
  {
  cb = ((CheckBox)(GridView1.Rows[i].FindControl("cb")));
  if (cb.Checked)
  {
  DataRow r = tb.NewRow();
  r[0] = Convert.ToInt32(GridView1.Rows[i].Cells[1].Text);
  r[1] = GridView1.Rows[i].Cells[2].Text;
  r[2] = GridView1.Rows[i].Cells[3].Text;
  r[3] = Convert.ToInt32(GridView1.Rows[i].Cells[4].Text);
  tb.Rows.Add(r);
  }

//Now here write the code for inserting data in multipal tables, you have to write seperate insert command for each table

SqlConnection con = new SqlConnectio("Server=tiger;database=database1;uid=sa");
con.Open();

for(int j=0;j

{

//write the code for inserting data in tables
 }

  Was this answer useful?  Yes

Give your answer:

If you think the above answer is not correct, Please select a reason and add your answer below.

 

Related Answered Questions

 

Related Open Questions