嗨,我的aspx页面中有一个网格。当用户单击网格中的上移和下移按钮时,网格行应该上下移动。
我在此处禁用第一行“向上”按钮以及最后一行“向下”按钮。
这很好但是当我向网格插入“PAGING”时上下移动仅适用于该页面。例如,我无法将我的第二页数据移动到第一页。
每个页面的顶行向上和向下按钮被禁用。所以我不能将我的第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();
}
答案 0 :(得分:0)
我认为你应该这样做:请在分页索引结束时启用除最后一行i之外的每一行的按钮。你可以利用count来做这个。并对list的第一项做同样的事情。希望这对你有用。