Click here to Skip to main content
15,846,343 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have grid view in which i want to select the multiple rows with the check box and i want to delete that rows but it showing an error
Quote:
Index was out of range. Must be non-negative and less than the size of the collection.
Parameter name: index

here is the code please help me

protected void btnDelete_Click(object sender, EventArgs e)
       {

           foreach (GridViewRow gvrow in Grid.Rows)
           {

               CheckBox chkdelete = (CheckBox)gvrow.FindControl("chkdelete");

               if (chkdelete.Checked)
               {
                   int usrid = Convert.ToInt32(Grid.DataKeys[gvrow.RowIndex].Value.ToString());
                   objUsers.DeleteParameters["Id"].DefaultValue = usrid.ToString();
                   objUsers.Delete();


                   BindEmployeeDetails();

               }
           }
       }
   }
Posted
Updated 1-May-13 9:04am
v2

C#
void DoSomething()
{
    foreach (GridViewRow gvrow in Grid.Rows)
    {
        List<int> lst = new List<int>();
        CheckBox chkdelete = (CheckBox)gvrow.FindControl("chkdelete");

        if (chkdelete.Checked)
        {
            int usrid = Convert.ToInt32(Grid.DataKeys[gvrow.RowIndex].Value.ToString());
            lst.Add(usrid);
            objUsers.DeleteParameters["Id"].DefaultValue = usrid.ToString();
            objUsers.Delete();
        }
    }
 
    BindEmployeeDetails();
}
 
Share this answer
 
v2
can any body help me? Please.............................
 
Share this answer
 
Comments
Naz_Firdouse 2-May-13 9:58am    
Don't add your comments as Answer... delete it...

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