我正在启用分页的gridview。
当我尝试删除第1页以外的页面上的行时,它会删除不正确的行,而不是删除按下删除按钮的行。
protected void GVRequest_RowDeleting(object sender, GridViewDeleteEventArgs e)
{
int index = Convert.ToInt32(e.RowIndex);
DataTable dtCurrentTable = ViewState["CurrentTable"] as DataTable;
dtCurrentTable.Rows[index].Delete();
ViewState["CurrentTable"] = dtCurrentTable;
DataView view = new DataView(dtCurrentTable);
DataTable dt1 = view.ToTable(true, "CartonID", "FileID", "FileMasterID", "DeptFileID", "RequestID");
GVRequest.DataSource = dt1;
DataBind();
}
答案 0 :(得分:0)
试试这个
替换你的
dtCurrentTable.Rows[index].Delete();
带
dtCurrentTable.Rows[index-1].Delete();
答案 1 :(得分:0)
试试这个......
protected void GVRequest_RowDeleting(object sender, GridViewDeleteEventArgs e)
{
int p = Convert.ToInt32(ViewState["Pageindex"]);
int s = GVRequest.PageSize;
p = p * s;
DataTable dtCurrentTable= new DataTable();
int d = Convert.ToInt32(e.RowIndex);
int dl = d + p;
dt = ViewState["CurrentTable"] as DataTable;
dtCurrentTable.Rows[dl].Delete();
ViewState["CurrentTable"] = dtCurrentTable;
DataView view = new DataView(dtCurrentTable);
DataTable dt1 = view.ToTable(true, "CartonID", "FileID", "FileMasterID", "DeptFileID", "RequestID");
GVRequest.DataSource = dt1;
DataBind();
ViewState["Pageindex"] = 0;
}
protected void NextPage(object sender, GridViewPageEventArgs e)
{
GVRequest.PageIndex = e.NewPageIndex;
ViewState["Pageindex"] = e.NewPageIndex;
GVRequest.DataSource = ViewState["CurrentTable"] as DataTable; //get datasource (list or datatable)
DataBind();
}
如果您使用上述代码
,则不想做任何事情