Click here to Skip to main content
15,896,269 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,
I want to update row of My GridView Control
I am able to edit but updated data is not reflecting in database as well as UI.

Here Below is my code

protected void UpdateEmployee(object sender, GridViewUpdateEventArgs e)

       {

           TextBox EmployeeID =(TextBox)GridView1.Rows[e.RowIndex].FindControl("txtEmployeeID");

           TextBox EnterpriseID = (TextBox)GridView1.Rows[e.RowIndex].FindControl("txtEnterpriseID");

           TextBox EmployeeName = (TextBox)GridView1.Rows[e.RowIndex].FindControl("txtEmployeeName");

           TextBox Hobbies = (TextBox)GridView1.Rows[e.RowIndex].FindControl("txtHobbies");

           TextBox ContactDetails = (TextBox)GridView1.Rows[e.RowIndex].FindControl("txtContactDetails");

           TextBox Details = (TextBox)GridView1.Rows[e.RowIndex].FindControl("txtDetails");

           using (SqlConnection Sqlcon = new SqlConnection(strCon))
           {

               using (SqlCommand cmd = new SqlCommand())
               {
                   Sqlcon.Open();
                   cmd.Connection = Sqlcon;
                   cmd.CommandType = CommandType.StoredProcedure;
                   cmd.CommandText = "spEmployee";
                   cmd.Parameters.Add(new SqlParameter("@ActionId", SqlDbType.VarChar, 15));
                   cmd.Parameters.Add(new SqlParameter("@EmployeeID", SqlDbType.BigInt));
                   cmd.Parameters.Add(new SqlParameter("@EnterpriseID", SqlDbType.VarChar, 25));
                   cmd.Parameters.Add(new SqlParameter("@EmployeeName",SqlDbType.VarChar,50));
                   cmd.Parameters.Add(new SqlParameter("@Hobbies", SqlDbType.VarChar, 50));
                   cmd.Parameters.Add(new SqlParameter("@ContactDetails", SqlDbType.BigInt));
                   cmd.Parameters.Add(new SqlParameter("@Details", SqlDbType.VarChar, 50));
                   cmd.Parameters["@ActionId"].Value = "UPDATE";
                   cmd.Parameters["@EnterpriseID"].Value = EnterpriseID.Text.Trim();
                   cmd.Parameters["@EmployeeName"].Value = EmployeeName.Text.Trim();
                   cmd.Parameters["@Hobbies"].Value = Hobbies.Text.Trim();
                   cmd.Parameters["@Details"].Value = Details.Text.Trim();
                   cmd.ExecuteNonQuery();
               }
               GridView1.EditIndex = -1;

               lblMessage.Text = "Record updated successfully!";

           }

       }


       RowCancelingEdit="CancelEdit"
       OnRowEditing="EditEmployee"
       OnRowUpdating="UpdateEmployee"
Posted

1 solution

 
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