简体   繁体   English

如何将值添加到RadioButtonList

[英]How to add a value to a RadioButtonList

Can anyone show how I would add a value of 0 to the wrong answers and aa value of 1 to the correct one? 谁能说明我如何将0的值添加到错误的答案,并将a的值添加到正确的答案?

protected void Page_Load(object sender, EventArgs e)
{   
    //Question
    lblQuestion1.Text = "Which of the following is not a country in Europe?";

    //Answers
    lstAns1.Items.Add("Enland");
    lstAns1.Items.Add("Germany");
    lstAns1.Items.Add("France");
    lstAns1.Items.Add("Canada");
}

I think you may add ListItems instead of only text. 我认为您可以添加ListItems而不是仅添加文本。

protected void Page_Load(object sender, EventArgs e)
{   
    if (!Page.IsPostBack)
    {
        //Question
        lblQuestion1.Text = "Which of the following is not a country in Europe?";

        //Answers
        lstAns1.Items.Add(new ListItem("Enland", "0"));
        lstAns1.Items.Add(new ListItem("Germany", "0"));
        lstAns1.Items.Add(new ListItem("France", "0"));
        lstAns1.Items.Add(new ListItem("Canada", "1"));
    }
}

I have added a check if this page is loaded by HTTP Get or by HTTP Post (see: Page.IsPostBack ). 我添加了检查此页面是否通过HTTP Get或HTTP Post加载的方法(请参阅: Page.IsPostBack )。

Anyway - this code is completely static.... You may think it over once again. 无论如何-此代码是完全静态的。...您可能会再考虑一遍。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM