Home > Software design >  moving rows between two data grid views
moving rows between two data grid views

Time:08-26

I have two data grid views with button fields. I have to grant and revoke functions to as particular role. if I click the grant button it should be removed from the current grid view and should be shown in the other grid view. that's the scenario with both grid views. I have used databinding() from database in every click. it works fine but the problem is that when I click the button it moves to the top of the grid due to the data binding. I want to maintain the current position of the grid view without moving to the top. Any ideas? TIA.enter image description here

here is the code behind

protected void grdAllFunctions_RowCommand(object sender, GridViewCommandEventArgs e)
    {
        int roleid = Convert.ToInt32(ddlUser.SelectedValue);
        int rowIndex = Convert.ToInt32(e.CommandArgument);
        GridViewRow row = grdAllFunctions.Rows[rowIndex];
        int funcid = Convert.ToInt32(row.Cells[0].Text);
        UserClass obj = new UserClass();
        try
        {
            if (ddlUser.SelectedValue == "0")
            {
                errorHandle(false, "Please Select the Role Name");
                return;
            }
            else
            {
                DataSet ds = new DataSet();
                ds.Merge(obj.checkgrantedfunctions(roleid, funcid));
                if (ds.Tables[0].Rows.Count > 0)
                {
                    errorHandle(false, "This Function is Already Assigned");
                    return;
                }
                else
                {
                    obj.grant(roleid, funcid);
                    errorHandle(true, "Successfully Granted");
                    DataSet dg = new DataSet();
                    dg.Merge(obj.ungrantedfunctions(roleid));
                    if (dg.Tables[0].Rows.Count > 0)
                    {
                        grdAllFunctions.DataSource = null;
                        grdAllFunctions.DataSource = dg.Tables[0];
                        grdAllFunctions.DataBind();
                    }
                    else
                    {
                        grdAllFunctions.DataSource = dg.Tables[0];
                        grdAllFunctions.DataBind();
                    }
                    DataSet ds1 = new DataSet();
                    ds1.Merge(obj.grantedfunctions(roleid));
                    if (ds1.Tables[0].Rows.Count > 0)
                    {
                        grdGrantedFunctions.Visible = true;
                        grdGrantedFunctions.DataSource = ds1.Tables[0];
                        grdGrantedFunctions.DataBind();
                    }
                    return;
                }
            }
        }
        catch (Exception ex)
        {
            Response.Write("<script>alert('"   Server.HtmlEncode(ex.Message)   "')</script>");
            return;
        }
    }

CodePudding user response:

At the end (after databinding), add a statement to focus on the next or previous GridViewRow - GridView.Rows[{Next or Previous}].Focus();

CodePudding user response:

scrollable GV in a div is the problem. paging resolves the problem. Follow This Method

  • Related