how to insert dropdownlist value, text box value and gridviews multiple selected rows together?
dwopodowns value and text box value will have to add with every checked rows of gridview in to database together.
outside dropdowns value and text box value will be same for every checked gridview rows.
please see the attached screenshot of the marks entry of the particular class for all students.
What I have tried:
string mainconn = ConfigurationManager.ConnectionStrings["constr"].ConnectionString;
foreach(GridViewRow grow in gridmarks.Rows)
{
var checkboxselect = grow.FindControl("chkRow") as CheckBox;
if(checkboxselect.Checked)
{
SqlConnection conn = new SqlConnection(mainconn);
string sqlquery = "insert into marksenters values (@enterdate, @Session, @sclass, @ssec, @sterm, @ssubject, @hmarks, @sroll, @sregdid, @ssname, @wmarks, @omarks, @stotal, @savg)";
SqlCommand sqlcomm = new SqlCommand(sqlquery, conn);
sqlcomm.parameters.addwithvalue("@enterdate", (grow.findcontrol("lbldate") as DropDownList).Text);
sqlcomm.parameters.addwithvalue("@session", (grow.findcontrol("ddlyear") as DropDownList).text);
sqlcomm.parameters.addwithvalue("@sclass", (grow.findcontrol("ddl_class") as DropDownList).text);
sqlcomm.parameters.addwithvalue("@ssec", (grow.findcontrol("ddl_section") as DropDownList).text);
sqlcomm.parameters.addwithvalue("@sterm", (grow.findcontrol("ddl_term") as DropDownList).text);
sqlcomm.parameters.addwithvalue("@ssubject", (grow.findcontrol("ddl_sub") as label).text);
sqlcomm.parameters.addwithvalue("@hmarks", (grow.findcontrol("optheighstmarks") as label).text);
sqlcomm.parameters.addwithvalue("@sroll", (grow.findcontrol("lblsroll") as label).text);
sqlcomm.parameters.addwithvalue("@sregdid", (grow.findcontrol("lblsid") as label).text);
sqlcomm.parameters.addwithvalue("@ssname", (grow.findcontrol("lblsname") as label).text);
sqlcomm.Parameters.AddWithValue("@wmarks", (grow.FindControl("txt_wmarks") as TextBox).Text);
sqlcomm.Parameters.AddWithValue("@omarks", (grow.FindControl("txt_omarks") as TextBox).Text);
sqlcomm.Parameters.AddWithValue("@stotal", (grow.FindControl("txt_total") as TextBox).Text);
sqlcomm.Parameters.AddWithValue("@savg", (grow.FindControl("txt_average") as TextBox).Text);
conn.Open();
sqlcomm.ExecuteNonQuery();
conn.Close();
lblmsg.Text = "saved successfully";
}
}