简体   繁体   中英

ASP.Net Gridview not rebind data on button click

i am new in asp.net i using LINQ with asp.net on button click event my gridview not rebind data and yes gridview is into the updatepanel

'> '>

protected void btnSave_Click(object sender, EventArgs e)
{
    foreach (GridViewRow gvr in gvClientData.Rows)
    {

        if (((CheckBox)gvr.FindControl("chkdisplay")).Checked == true)
        {
            string Index = ((Label)gvr.FindControl("lblIndex")).Text;
            int GIIndex = Convert.ToInt32(Index);
            GI_InsureMaster insertclientinfo = vjdb.GI_InsureMasters.Single(upd => upd.GIMastIndex == GIIndex);
            insertclientinfo.SendToCompany = true;
            vjdb.SubmitChanges();
        }

    }
    BindAgencyData();
    Response.Redirect(Request.RawUrl);
}

It seems you are trying to modify an object and then saving it back to the DB, but you are doing it wrong.

You are querying the object from a different Data Context, vjdb and you are calling SubmitChanges on linqobject . You should call SubmitChanges on vjdb

protected void btnSave_Click(object sender, EventArgs e)
{
    foreach (GridViewRow gvr in gvClientData.Rows)
    {

        if (((CheckBox)gvr.FindControl("chkdisplay")).Checked == true)
        {
            string Index = ((Label)gvr.FindControl("lblIndex")).Text;
            int GIIndex = Convert.ToInt32(Index);
            GI_InsureMaster insertclientinfo = vjdb.GI_InsureMasters.Single(upd => upd.GIMastIndex == GIIndex);
            insertclientinfo.SendToCompany = true;
            vjdb.SubmitChanges(); //HERE
        }

    }
    BindAgencyData();
    Response.Redirect(Request.RawUrl);
}

Assuming that BindAgencyData is querying database for latest/updated record and then binding the data to the grid.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM