خرید بک لینک

مشکل این کد چیه ؟

چرا بعد از اینکه روی دکمه میزنم ارور میده

 protected void BindGrid()
{
GridView2.DataSource = ViewState["Users"] as DataTable;
GridView2.DataBind();
}

protected void GridView2_RowDeleting(object sender, GridViewDeleteEventArgs e)
{
int index = Convert.ToInt32(e.RowIndex);
DataTable dt = ViewState["Users"] as DataTable;
dt.Rows[index].Delete();
ViewState["Users"] = dt;
BindGrid();
}
protected void GridView2_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
string item = e.Row.Cells[0].Text;
foreach (Button button in e.Row.Cells[2].Controls.OfType<Button>())
{
if (button.CommandName == "Delete")
{
button.Attributes["onclick"] = "if(!confirm('Do you want to delete " + item + "?')){ retu false; };";
}
}
}
}

به این خط ارور میده

dt.Rows[index].Delete();

برای پاک کردن یک سطر چیز دیگر هم میخواد ؟

راستی تیبل ها و سطر ها کجا باید تعریف بشه ؟

نمونه کد ساده ندارید که ازش استفاده کنم ؟

برچسب: نویسنده: محمد رضا جوادیان تاريخ: جمعه 20 فروردين 1395 ساعت: 18:12

صفحه بندی