2015-03-08 46 views
0

任何人都可以顯示我將如何將0值添加到錯誤的答案和值爲1到正確的?如何將值添加到RadioButtonList

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"); 
} 
+1

請解釋一下你想添加0或1的值嗎? – 2015-03-08 16:54:17

+0

如果可能,我希望在頁面加載事件中包含所有內容 – 2015-03-08 16:54:50

+0

您的問題尚不清楚。請給出一些示例輸出。瞭解你的問題會有幫助。 – 2015-03-08 16:59:55

回答

0

我想你可能會添加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")); 
    } 
} 

如果該網頁的HTTP GET或HTTP郵政(:Page.IsPostBack見)裝我加了檢查。

無論如何 - 這個代碼是完全靜態的....你可能會再次考慮它。

+0

謝謝你的幫助 – 2015-03-08 17:08:00