即使我检查了,RadioButtonlist项目它取值为null。这是我的代码帮助我

时间:2016-11-01 20:10:38

标签: asp.net radiobuttonlist

我以编程方式分配了radiobuttonlist项目。我希望radiobuttonlist项目被检查/不检查我想要检查项目与另一个值进行比较,如果相等的增量分数,否则我没有写任何代码,但在调试时,即使我检查了项目它取空值请帮帮我......

public void assign()
{
    Label2.Text = ques[(int)ViewState["value"]];
    RadioButtonList1.Items.Clear();
    RadioButtonList1.Items.Add(new ListItem(opt1[(int)ViewState["value"]], "0"));
    RadioButtonList1.Items.Add(new ListItem(opt2[(int)ViewState["value"]], "1"));
    RadioButtonList1.Items.Add(new ListItem(opt3[(int)ViewState["value"]], "2"));
    RadioButtonList1.Items.Add(new ListItem(opt4[(int)ViewState["value"]], "3"));
    btn_Submit.Visible = false;
}

public void radiochecked()
{
    if (ViewState["index"] == null)
    {
        ViewState["index"] = 0;
    }
    crctans = (string[])Session["correctanswer"];
    if (RadioButtonList1.SelectedIndex > -1)
    {
        if (crctans[(int)ViewState["index"]] == RadioButtonList1.SelectedItem.Text)
        {
            score = score + 1;
        }
    }
    ViewState["index"] = (int)ViewState["index"] + 1;
    if ((int)ViewState["index"] == 10)
    {
        Session["result"] = score;
    }
}

protected void btn_Next_Click(object sender, EventArgs e)
{
    radiochecked();
}

0 个答案:

没有答案