0

嗨,我的 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();
    }
4

1 回答 1

0

我认为你应该这样做:请为除最后一行之外的每一行启用按钮,即当分页索引结束时。你可以利用计数来做到这一点。并对列表的第一项做同样的事情。希望这会对你有所帮助。

于 2013-10-01T06:25:25.667 回答