如何从正确选项的单选按钮和comapre中获取所选值? [英] How can I get the selected value from radio button and comapre with correct option ?

查看:69
本文介绍了如何从正确选项的单选按钮和comapre中获取所选值?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我从带有id的单选按钮获取值,这些单选按钮在转发器中。 rd4中的正确选项。我正在比较rd1,rd2和& rd3与rd4如果任何一个匹配然后计数+ 1否则计数保持为0然后这个计数结果我想在标签中显示。但结果连续显示0是否正确...



我尝试过:



I am getting values from radio buttons with id these radio button are in repeater . Correct option in rd4. I am comparing rd1,rd2, & rd3 with rd4 if any one matched then count+1 else count remains 0 then this count result i want to show in label .but result continuously shows 0 wether it is correct or not...

What I have tried:

 protected void Button1_Click(object sender, EventArgs e)
        {
            int count1=0 ;

           
            if (Repeater1.Items.Count > 0)
            {
                for (int count = 0; count < Repeater1.Items.Count; count++)
                {
                    RadioButton rd1 = (RadioButton)Repeater1.Items[count].FindControl("RadioButton1");
                    RadioButton rd2 = (RadioButton)Repeater1.Items[count].FindControl("RadioButton2");
                    RadioButton rd3 = (RadioButton)Repeater1.Items[count].FindControl("RadioButton3");
                    RadioButton rd4 = (RadioButton)Repeater1.Items[count].FindControl("RadioButton31");
    if (rd1.Checked)
                    {
                        if (rd1 == rd4)
                        {
                            count1++;
                        }
                        else
                        {
                            count1 = count1 + 0;
                        }


                    }
                    if (rd2.Checked)
                    {
                        if (rd2 == rd4)
                        {
                            count1++;
                        }
                        else
                        {
                            count1 = count1 + 0;
                        }

                    }
                    if (rd3.Checked)
                    {
                        if (rd3 == rd4)
                        {
                            count1++;
                        }
                        else
                        {
                            count1 = count1 + 0;
                        }

                    }

            Label1.Text = Convert.ToString(count1);
}

推荐答案

为什么不简单地给一个值,例如1给正确答案(它的单选按钮),如果值为1,则将该条件添加为得分计数。



例如

if(rd ==1)

{

count + = 1;

返回

}

Label1。 Text = Convert.ToString(count1);
Why not simply assign a value, e.g "1" to the correct answer (it's radio button), then put that condition that adds the count for score if the value is 1.

e.g
if(rd=="1")
{
count += 1;
return
}
Label1.Text = Convert.ToString(count1);


这篇关于如何从正确选项的单选按钮和comapre中获取所选值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆