how loop through multiple checkbox in C#

前端 未结 6 1052
后悔当初
后悔当初 2021-01-14 00:06

I have 100 checkbox in a winfrom. Their name is sequential like checkbox1,checkbox2 etc. I have a submit button in my winform. After clicking the submitting button, it check

6条回答
  •  时光说笑
    2021-01-14 00:51

    This is the write answer for this................

    c#

               string movie="";
               if (checkBox1.Checked == true)
                {
                    movie=movie+checkBox1.Text + ",";
                }
                if (checkBox2.Checked == true)
                {
                    movie=movie+checkBox2.Text + ",";
                }
                if (checkBox3.Checked == true)
                {
                    movie=movie+checkBox3.Text + ",";
                }
    
                if (checkBox4.Checked == true)
                {
                    movie = movie + checkBox4.Text + ",";
                }
                if (checkBox5.Checked == true)
                {
                    movie = movie + checkBox5.Text + ",";
                }
                if (checkBox6.Checked == true)
                {
                    movie = movie + checkBox6.Text + ",";
                }
              row["EnquiryFor"] = movie.ToString();
    

    where row is a object of DataRow and EnquiryFor is the name of sql table column....

提交回复
热议问题