sir,
my web-form is questionniare and it consists of ten questions whose answers are yes or no in radio button format , i want to count the number of yes radio buttons selected and no radio buttons selected in display them in two text-boxes yes and no respectively. kindly suggest me something on this
thanking you
Pankaj Kumar ChoudharyPosted Mar 4, 2015, 12:24 PM
int yes = 0;
int no = 0;
foreach (Control ctrl in this.Page.Controls)
{
if (ctrl is RadioButton)
{
if (((RadioButton)ctrl).Checked == true)
{
if (((RadioButton)ctrl).Text == "yes")
yes++;
else if (((RadioButton)ctrl).Text == "no")
no++;
}
}
}
TextBox1.Text = yes.ToString() ;
TextBox2.Text = no.ToString();