Click here to Skip to main content
15,901,035 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Index was out of range. Must be non-negative and less than the size of the collection.
Parameter name: index

C#
protected void btnDelete_Click(object sender, EventArgs e)
{
foreach (GridViewRow row in gv_1.Rows)
{

CheckBox cb = (CheckBox)row.FindControl("checkBoxD");

if (cb.Checked)
{

BBLL delBLL = new BBLL();

string message = "";

int foodID = Convert.ToInt32(gv_1.DataKeys[row.RowIndex].Value);
message = evtBLL.Delete(foodtID);


gv_1.DataBind();


}

}
Posted
Updated 7-Feb-14 0:57am
v2

1 solution

i think the problem is here

C#
if(gv_1.RowIndex > 0)
            {
int foodID = Convert.ToInt32(gv_1.DataKeys[row.RowIndex].Value);
message = evtBLL.Delete(foodtID);
}
 
Share this answer
 
Comments
Member 10574155 7-Feb-14 7:49am    
So what I need to change
Sumit_Pathak 7-Feb-14 22:12pm    
just put if condition like above code

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