嗨,我的 aspx 页面中有一个网格。当用户单击网格中的上移和下移按钮时,网格行应该上下移动。
我在这里禁用了第一行“向上”按钮以及最后一行“向下”按钮。
这工作正常,但是当我将“分页”插入网格时,上下移动仅适用于该页面。例如,我无法将我的第二页数据移动到第一页。
每页顶行上下按钮禁用。所以我不能将我的第 3 页行数据移动到第 1 页。
这是我的代码..
protected void BindGridview()
{
con.Open();
//cmd = new SqlCommand("select * from MobileDetails order by Priority asc", con);
cmd = new SqlCommand("select IDCHECKITEM,CHECKITEM,DESCRIPTION,SORTORDER from CHECKITEM order by SORTORDER asc", con);
da = new SqlDataAdapter(cmd);
DataSet ds = new DataSet();
da.Fill(ds);
con.Close();
gvUserInfo.DataSource = ds;
gvUserInfo.DataBind();
GridViewRow FirstRow = gvUserInfo.Rows[0];
Button btnUp = (Button)FirstRow.FindControl("btnUp");
btnUp.Enabled = false;
GridViewRow LastRow = gvUserInfo.Rows[gvUserInfo.Rows.Count - 1];
Button btnDown = (Button)LastRow.FindControl("btnDown");
btnDown.Enabled = false;
}
protected void gvUserInfo_RowDataCommand(object sender, GridViewCommandEventArgs e)
{
int index = 0;
GridViewRow gvrow;
GridViewRow previousRow;
if (e.CommandName == "Up")
{
index = Convert.ToInt32(e.CommandArgument);
gvrow = gvUserInfo.Rows[index];
previousRow = gvUserInfo.Rows[index - 1];
int mobilesort = Convert.ToInt32(gvUserInfo.DataKeys[gvrow.RowIndex].Value.ToString());
//int mobilePriority = Convert.ToInt32(gvUserInfo.DataKeys[gvrow.RowIndex].Value.ToString());
int mobileId = Convert.ToInt32(gvrow.Cells[0].Text);
int previousId = Convert.ToInt32(previousRow.Cells[0].Text);
con.Open();
cmd = new SqlCommand("update CHECKITEM set SORTORDER='" + (mobilesort - 1) + "' where IDCHECKITEM='" + mobileId + "'; update CHECKITEM set SORTORDER='" + (mobilesort) + "' where IDCHECKITEM='" + previousId + "'", con);
cmd.ExecuteNonQuery();
con.Close();
}
if (e.CommandName == "Down")
{
index = Convert.ToInt32(e.CommandArgument);
gvrow = gvUserInfo.Rows[index];
previousRow = gvUserInfo.Rows[index + 1];
int mobilesort = Convert.ToInt32(gvUserInfo.DataKeys[gvrow.RowIndex].Value.ToString());
int mobileId = Convert.ToInt32(gvrow.Cells[0].Text);
int previousId = Convert.ToInt32(previousRow.Cells[0].Text);
con.Open();
cmd = new SqlCommand("update CHECKITEM set SORTORDER='" + (mobilesort + 1) + "' where IDCHECKITEM='" + mobileId + "'; update CHECKITEM set SORTORDER='" + (mobilesort) + "' where IDCHECKITEM='" + previousId + "'", con);
cmd.ExecuteNonQuery();
con.Close();
}
BindGridview();
}
protected void gvUserInfo_PageIndexChanging(object sender, GridViewPageEventArgs e)
{
gvUserInfo.PageIndex = e.NewPageIndex;
BindGridview();
}