Click here to Skip to main content
15,912,400 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Dear all,

I want To insert data in database using checkboxlist in gridview

by check the data i want to insert from checkboxlist foreach row

the Error :
data insert one row only every time i click on Submit button

i want to insert data for all rows at same time

this is my code




C#
protected void Butaddgang_Click(object sender, EventArgs e)
   {

   inserlaborgangs inlabgang = new inserlaborgangs();

       for (int i = 0; i < GridView1.Rows.Count; i++)
       {
           if (GridView1.Rows[i].RowType == DataControlRowType.DataRow)
           {


               int labfilenoo = (int)GridView1.DataKeys[i].Value;
               CheckBoxList gang = (CheckBoxList)GridView1.Rows[i].FindControl("RadioButtongang");

               TextBox remarks = (TextBox)GridView1.Rows[i].FindControl("Textremarks");

               // add parameters
               inlabgang.labfileno = labfilenoo;
               inlabgang.Remarks = remarks.Text;



               if (gang.SelectedIndex > -1)
               {

                   inlabgang.gangid = int.Parse(gang.SelectedValue.ToString());
                   inlabgang.formanid = 0;
                   inlabgang.Add();
                   inlab.Update();

                   LblMsg.Text = "Done";
                   Page.DataBind();

               }





           }


       }
Posted

As per Solution 1, you should Bind after update.

And if you want to update one time, then follow - Edit Update Delete Multiple Records/Rows Gridview With Checkbox[^], there are two methods.
Follow the one which you like.
 
Share this answer
 
put the lines Page.DataBind outside the for loop and check
 
Share this answer
 

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