protected void btnDelete_Click(object sender, EventArgs e)
{
//Loop through all the rows in gridview
foreach (GridViewRow GridViewrow in GridView1.Rows)
{
//Finiding checkbox control in gridview for particular row
CheckBox chkdelete = (CheckBox)GridViewrow.FindControl("chkdelete");
//Condition to check checkbox selected or not
if (chkdelete.Checked)
{
//Getting UserId of particular row using datakey value
int Sno = Convert.ToInt32(GridView1.DataKeys[GridViewrow.RowIndex].Value);
SqlDataSource1.DeleteParameters["Sno"].DefaultValue =Sno.ToString();
SqlDataSource1.Delete();
}
when i wanted to execute this one getting this error:
Index was out of range. Must be non-negative and less than the size of the collection. Parameter name: index
when i wanted to execute this one getting this error:
Index was out of range. Must be non-negative and less than the size of the collection. Parameter name: index
Parameswari beraPosted Mar 5, 2015, 1:22 AM
Manish Kumar ChoudharyPosted Mar 5, 2015, 12:56 AM
Go through following links it will help you
http://www.c-sharpcorner.com/UploadFile/1e050f/delete-records-from-gridview-using-checkbox-in-Asp-Net/
http://www.aspsnippets.com/Articles/Delete-multiple-rows-in-GridView-with-CheckBox-selection-and-with-confirmation-in-ASPNet.aspx