Click here to Skip to main content
15,904,416 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
C#
protected void GridView2_RowUpdating(object sender, GridViewUpdateEventArgs e)
    {
     
        GridViewRow row = (GridViewRow)GridView2.Rows[e.RowIndex];
        int BookingRefNo=int.Parse(GridView2.DataKeys[e.RowIndex].Value.ToString());
             
        string AssignedPriority = ((TextBox)row.Cells[11].Controls[0]).Text;
        string Status = ((TextBox)row.Cells[12].Controls[0]).Text;

        
        SqlConnection con1 = new SqlConnection(constr);
        SqlCommand cmd = new SqlCommand("Update TSafetyMaster set AssignedPriority=@AssignedPriority,Status=@Status where BookingRefNo=@BookingRefNo", con1);
        cmd.Parameters.Add("@BookingRefNo", SqlDbType.Int).Value = BookingRefNo;
        cmd.Parameters.Add("@AssignedPriority", SqlDbType.VarChar).Value = AssignedPriority;
        cmd.Parameters.Add("@Status", SqlDbType.NVarChar).Value = Status;
        con1.Open();
        cmd.ExecuteNonQuery();
        GridView2.EditIndex=-1;
        GridView2.DataBind();
        
    }
Posted
Updated 15-May-14 0:37am
v2
Comments
Prasad Avunoori 15-May-14 6:43am    
Use Try, Catch blocks and let us know exact error message.
thursunamy 15-May-14 10:15am    
As I can see after your update operation you dont refresh the data source of the grid. You may define the code which you are filling the grid as a method like 'FillGrid()' and then you may call that method after your update operation.
safihur Rahuman 17-May-14 0:33am    
pls tell me where we want to change....

1 solution

safihur Rahuman...

USE DataSet for storing temparary data when you update any row from GridView control..

whenever you make changes to DATA in GridView control... reflect those changes to DataSet ...and then SET the same table from DataSet for DataSource Property of Griview.


It's a good way to update bulk data changes to DATABASE Once at all...


Your programming approach of Opening & Closing Database Connection is Very Good...BUT if you do it for each Row will be time consuming..




Happy Programming....:-)
 
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