protected void save(object sender, EventArgs e)
{
Control control = null;
if (GridView1.FooterRow != null)
{
control = GridView1.FooterRow;
}
else
{
control = GridView1.Controls[0].Controls[0];
}
string empname = (control.FindControl("txtempName") as TextBox).Text;
string empcode = (control.FindControl("txtempcode") as TextBox).Text;
string department = (control.FindControl("DropDownList2") as DropDownList).Text;
string salary = (control.FindControl("txtsalary") as TextBox).Text;
string gender = (control.FindControl("RadioButtonList2") as RadioButtonList).Text;
string strConnString = ConfigurationManager.ConnectionStrings["conn"].ConnectionString;
StringCollection sc = new StringCollection();
ListBox project = GridView1.FooterRow.FindControl("ListBox2") as ListBox;
CheckBoxList skill = GridView1.FooterRow.FindControl("CheckBoxList1") as CheckBoxList;
foreach (ListItem selectedItem in project.Items)
{
if (selectedItem.Selected)
{
if (sVendors.Length == 0)
sVendors = selectedItem.Value;
else
sVendors = sVendors + "," + selectedItem.Value;
}
}
foreach (ListItem oItem in skill.Items)
{
if (oItem.Selected)
{
if (sSkill.Length == 0)
sSkill = oItem.Value;
else
sSkill = sSkill + "," + oItem.Value;
}
}
using (SqlConnection con = new SqlConnection(strConnString))
{
using (SqlCommand cmd = new SqlCommand())
{
cmd.Connection = con;
cmd.CommandType = CommandType.Text;
cmd.CommandText = "INSERT INTO [empdetails] VALUES(@empname, @empcode, @department,@salary, @gender, @sSkill,@sVendors)";
cmd.Parameters.AddWithValue("@empname", empname);
cmd.Parameters.AddWithValue("@empcode", empcode);
cmd.Parameters.AddWithValue("@department", department);
cmd.Parameters.AddWithValue("@salary", salary);
cmd.Parameters.AddWithValue("@gender", gender);
cmd.Parameters.AddWithValue("@sSkill", sSkill);
cmd.Parameters.AddWithValue("@sVendors", sVendors);
con.Open();
cmd.ExecuteNonQuery();
con.Close();
}
}
Response.Redirect(Request.Url.AbsoluteUri);
}
No comments:
Post a Comment