adineh67
شنبه 03 دی 1390, 16:47 عصر
سلام من واسه حذف پیام هام موقع کلیک روی دکمه ی حذف به این ارور می خورم :
Microsoft JScript runtime error: Sys.WebForms.PageRequestManagerServerErrorExceptio n: Index was out
of range. Must be non-negative and less than the size of the collection.
Parameter name: index
عملیات متوقف میشه و هیچ کاری نمی کنه علت چیه؟
کدی که نوشتم بصورت زیر هست:
protected void GridView1_RowCommand(object sender, GridViewCommandEventArgs e)
{
if (e.CommandName == "delete")
{
StringCollection sc = new StringCollection();
string id = string.Empty;
for (int i = 0; i < GridView1.Rows.Count; i++)//loop the GridView Rows
{
System.Web.UI.WebControls.CheckBox cb = (System.Web.UI.WebControls.CheckBox)GridView1.Rows[i].Cells[0].FindControl("CheckBox1"); //find the CheckBox
if (cb != null)
{
if (cb.Checked)
{
id = GridView1.Rows[i].Cells[2].Text; // get the id of the field to be deleted
sc.Add(id); // add the id to be deleted in the StringCollection
}
else
Response.Write("<script>alert('پیامی انتخاب نشده است');location.href='Admin.aspx'</script>");
}
}
DeleteRecords(sc); // call method for delete and pass the StringCollection values
BindData(); // Bind GridView to reflect changes made here
}
}
این اتفاق بلافاصله بعد از عبور از روی دستور if (e.CommandName == "delete") میفته:متعجب:
Microsoft JScript runtime error: Sys.WebForms.PageRequestManagerServerErrorExceptio n: Index was out
of range. Must be non-negative and less than the size of the collection.
Parameter name: index
عملیات متوقف میشه و هیچ کاری نمی کنه علت چیه؟
کدی که نوشتم بصورت زیر هست:
protected void GridView1_RowCommand(object sender, GridViewCommandEventArgs e)
{
if (e.CommandName == "delete")
{
StringCollection sc = new StringCollection();
string id = string.Empty;
for (int i = 0; i < GridView1.Rows.Count; i++)//loop the GridView Rows
{
System.Web.UI.WebControls.CheckBox cb = (System.Web.UI.WebControls.CheckBox)GridView1.Rows[i].Cells[0].FindControl("CheckBox1"); //find the CheckBox
if (cb != null)
{
if (cb.Checked)
{
id = GridView1.Rows[i].Cells[2].Text; // get the id of the field to be deleted
sc.Add(id); // add the id to be deleted in the StringCollection
}
else
Response.Write("<script>alert('پیامی انتخاب نشده است');location.href='Admin.aspx'</script>");
}
}
DeleteRecords(sc); // call method for delete and pass the StringCollection values
BindData(); // Bind GridView to reflect changes made here
}
}
این اتفاق بلافاصله بعد از عبور از روی دستور if (e.CommandName == "delete") میفته:متعجب: