Click here to Skip to main content
15,896,063 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello ,


I have a requirement in which i am updating values in a gridview based upon no of rows selected by the checkbox field.


//Variable Decleratins
C#
for(int index =0;index<dt1.Rows.Count;index++)
               {
                   CheckBox chkselect = (CheckBox)grdReplicate.Rows[index].FindControl("chkSelect");
                   if (chkselect.Checked == true)
                   {
                       if (res == "")
                       {
                           lblppo=(Label)grdReplicate.Rows[index].FindControl("lblgrdppono");
                           res = Convert.ToString(grdReplicate.DataKeys[index].Value);
                           ppoids = lblppo.Text;
                       }
                   }


LblMsg = Penobj._ExecuteQuery("update t_replicate_detail set MICR_CODE='" + (grdReplicate.Rows[index].Cells[8].Text)+ " ' where Replicate_ID in( '" + res + "')");



But Iam not able to retrive the particular cell value in the gridview.How to go about it?
Posted

1 solution

Grid view is not automatically sync with database. It is sync with the in memory cache of the datasource. You are updating the database doesn't mean the gridview got updated. You need to refresh (query database and retrieve data) the datasource and rebind the grid view.

Generally changes affect the data source first,before it update the database. For example a dataset will be updated first and then call the data adapter's update method or update a linq context object and the the submit changes method sync all necessary things. In your case you are directly updating the values to the database. So you need to retrieve it and bind to the gridview after updated.

Another thing, your method Penobj._ExecuteQuery doing a update. I guess it calls an ExecuteNonQuery which will not return back anything. So I doubt you will get anything here LblMsg =

Follow the ways the data travel from control to database and come back to the gridviews datasource. if it stuck somewhere you may post here. Our experts will be happy to help you.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900