[英]Gridview up and down
Hi I have a grid in my aspx page. 嗨,我的aspx页面中有一个网格。 The grid rows should moves up and down when the user click the move up and move down button in the grid.
当用户单击网格中的上移和下移按钮时,网格行应上下移动。
I disable the First row "UP" button as well as Last row "DOWN" button here. 我在这里禁用了第一行“上”按钮以及最后一行“下”按钮。
This works fine but when i insert "PAGING" to the grid Move up and down works only in that page only. 这工作正常,但是当我在网格中插入“ PAGING”时,仅在该页面上上下移动。 For example i cant move my 2nd page data to the 1st page.
例如,我无法将我的第二页数据移动到第一页。
Each page the top row up and down button disabled. 每个页面的第一行上和下按钮都被禁用。 so that i cant move my 3rd page row data to 1st page.
这样我就无法将我的第三页行数据移动到第一页。
Here is my code.. 这是我的代码。
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();
}
I think u should do like this: pls enable the button for every row except the last row i,e when the paging index ends. 我认为您应该这样做:请在分页索引结束时为除最后一行(即最后一行)之外的每一行启用按钮。 U can make use of count to do this.and do the same for the very first item of the list.Hope this will help u.
U可以利用count来做到这一点,并且对列表的第一项也可以做到这一点,希望对你有帮助。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.