Click here to Skip to main content
15,354,954 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
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)
       {
       //  //  bool select1 = Convert.ToBoolean(grow.Cells["chkRow"].value);
         var checkboxselect = grow.FindControl("chkRow") as CheckBox;
         if(checkboxselect.Checked)
          {
               SqlConnection conn = new SqlConnection(mainconn);
       //        //  string sqlquery = "insert into [shishumon_smsuser].[marksenters] values (@sroll, @sregdid, @ssname, @wmarks, @omarks, @stotal, @savg)";
       //       // string sqlquery = "insert into [shishumon_smsuser].[marksenters] values (@sroll, @sregdid, @ssname)";
              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";
          }
      }
Posted
Updated 19-Apr-22 17:48pm
v2
Comments
Richard Deeming 19-Apr-22 12:43pm
   
A bunch of commented-out code will do nothing.

Click the green "Improve question" link and update your question to include a clear description of what you are trying to do and where you are stuck. Include the relevant parts of your code, and the full details of any errors.

And no, you can't upload a screenshot.

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



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900