Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: ASP.NET
Hi,
 
Am unable to Update and Insert the values from Gridview, so please anybody can help me to solve this problem.
 
Here is My Source C# Code, and i will post my Source code in nex page.
 
protected void GridView1_RowUpdating(object sender, GridViewUpdateEventArgs e)
    {
 
        var EmpNo = GridView1.DataKeys[e.RowIndex].Value;
        //GridViewRow row = GridView1.Rows[e.RowIndex] as GridViewRow;
        //TextBox EmpNo = GridView1.FooterRow.FindControl("txtEmpNo") as TextBox;
        TextBox EmpName = GridView1.FooterRow.FindControl("txtEmpName") as TextBox;
        DropDownList Designation = GridView1.FooterRow.FindControl("dropDesg") as DropDownList;
        DropDownList Department = GridView1.FooterRow.FindControl("ddlDep") as DropDownList;
        TextBox Salary = GridView1.FooterRow.FindControl("txtSal") as TextBox;
        int test = 0;
        int.TryParse(Salary.Text, out test);
        RadioButtonList Gender = GridView1.FooterRow.FindControl("RBLGender") as RadioButtonList;
        CheckBoxList Preference = GridView1.FooterRow.FindControl("CheckBoxList1") as CheckBoxList;
 
        SqlConnection con = new SqlConnection("Server=****;uid=sa;password=*****; database=sreeramdasari;");
        //con.Open();
        SqlCommand cmd = new SqlCommand("Update EmployeeDetails set EmpName=@EmpName, Designation=@Designation,Department=@Department,Salary=@Salary,Gender=@Gender,Preference=@Preference where EmpNo=@EmpNo");
 
        cmd.Parameters.AddWithValue("@EmpNo", EmpNo);
        cmd.Parameters.AddWithValue("@EmpName", EmpName.Text.Trim());
        cmd.Parameters.AddWithValue("@Designation", Designation.Text.Trim());
        cmd.Parameters.AddWithValue("@Department", Department.Text.Trim());
        cmd.Parameters.AddWithValue("@Salary", Salary.Text.Trim());
        cmd.Parameters.AddWithValue("@Gender", Gender.Text.Trim());
        cmd.Parameters.AddWithValue("@Preference", Preference.Text.Trim());
        cmd.Connection = con;
        con.Open();
        cmd.ExecuteNonQuery();
 

 

        lbl1.Text = (" Record Updated Successfully");
        //Label6.Enabled = true;
        GridView1.EditIndex = -1;
   
   
 
        con.Close();
        this.BindGridView();
   
 
    }
Posted 28-Nov-12 19:30pm
Edited 28-Nov-12 19:32pm
28.9K
v2

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

  Print Answers RSS
0 Sergey Alexandrovich Kryukov 568
1 OriginalGriff 384
2 George Jonsson 258
3 Abdul Samad KP 135
4 Animesh Datta 130
0 OriginalGriff 6,099
1 Sergey Alexandrovich Kryukov 5,411
2 CPallini 4,770
3 George Jonsson 3,400
4 Gihan Liyanage 2,522


Advertise | Privacy | Mobile
Web04 | 2.8.140916.1 | Last Updated 29 Nov 2012
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100