ALOK SHARMA

ALOK SHARMA

  • NA
  • 51
  • 12.6k

Updating through gridview doesn't works

Feb 3 2014 5:45 AM
I am trying to update in gridview but it's not getting update 


Below is my coding

protected void GridView_Updating(object sender, GridViewUpdateEventArgs e)
    {

        SqlConnection con = new SqlConnection(@"Data Source=SONY-VAIO\SQLEXPRESS;Initial Catalog=Employee;Integrated Security=True");
        con.Open();
        Label lb = (Label)GridView.Rows[e.RowIndex].FindControl("Id");
        RadioButtonList rd = (RadioButtonList)GridView.Rows[e.RowIndex].FindControl("rdStatus");
        CheckBoxList cb = (CheckBoxList)GridView.Rows[e.RowIndex].FindControl("ChkActive");
        TextBox tx1 = (TextBox)GridView.Rows[e.RowIndex].FindControl("txtId");
        TextBox tx2 = (TextBox)GridView.Rows[e.RowIndex].FindControl("txtName");
        TextBox tx3= (TextBox)GridView.Rows[e.RowIndex].FindControl("txtAddress");
        DropDownList ddl = (DropDownList)GridView.Rows[e.RowIndex].FindControl("ddlDepartment");
        
        
        SqlCommand cmd = new SqlCommand("Update Edittable set Name=@Name , Address=@Address,Status=@Status,Active=@Active,Department=@Department,Salary=@Salary WHERE Id=@Id", con);
        cmd.Parameters.AddWithValue("@Id", txtId.Text.ToString());
        cmd.Parameters.AddWithValue("@Name", txtName.Text.ToString());
        cmd.Parameters.AddWithValue("@Address", txtAddress.Text.ToString());
        cmd.Parameters.AddWithValue("@Department", ddlDepartment.SelectedValue.ToString());
        cmd.Parameters.AddWithValue("@Salary", txtSalary.Text.ToString());
        cmd.Parameters.AddWithValue("@Active", ChkActive.SelectedValue.ToString());
        cmd.Parameters.AddWithValue("@Status", rdStatus.SelectedValue.ToString());
       
        cmd.ExecuteNonQuery();
       
        GridView.EditIndex = -1;
        FillGridView();
    }


Answers (18)