protected void GridView1_RowUpdating(object sender, GridViewUpdateEventArgs e) { Label lb = (Label)GridView1.Rows[e.RowIndex].FindControl("Label6"); DropDownList ddl = (DropDownList)GridView1.Rows[e.RowIndex].FindControl("DropDownList1"); RadioButtonList rbl = (RadioButtonList)GridView1.Rows[e.RowIndex].FindControl("RadioButtonList1"); CheckBoxList chb = (CheckBoxList)GridView1.Rows[e.RowIndex].FindControl("CheckBoxList2"); TextBox tx1 = (TextBox)GridView1.Rows[e.RowIndex].FindControl("TextBox1"); TextBox tx2 = (TextBox)GridView1.Rows[e.RowIndex].FindControl("TextBox2"); TextBox tx3 = (TextBox)GridView1.Rows[e.RowIndex].FindControl("TextBox3"); ListBox llb = (ListBox)GridView1.Rows[e.RowIndex].FindControl("ListBox1"); string ski = ""; foreach (ListItem selectedItem in chb.Items) { if (selectedItem.Selected) { if (ski.Length == 0) ski = selectedItem.Value; else ski = ski + "," + selectedItem.Value; } } string pro = ""; foreach (ListItem selectedItem in llb.Items) { if (selectedItem.Selected) { if (pro.Length == 0) pro = selectedItem.Value; else pro = pro + "," + selectedItem.Value; } } sqlcon = new SqlConnection(con); sqlcon.Open(); string sql = "update empdetails set empname='" + tx1.Text + "',empcode='" + tx2.Text + "',department='" + ddl.SelectedValue.ToString() + "',salary='" + tx3.Text + "',gender='" + rbl.SelectedValue.ToString() + "',skill='" + ski + "',project='" + pro + "' where empno='" + lb.Text + "'"; SqlCommand cmd = new SqlCommand(sql); cmd.CommandType = CommandType.Text; cmd.Connection = sqlcon; cmd.ExecuteNonQuery(); GridView1.EditIndex = -1; showgrid(); }
No comments:
Post a Comment