2014-12-20 139 views
0

我有一個帶有RadioButtonList的.aspx頁面上的窗體。我使用ArrayList和BindData()填充列表。當我嘗試獲取列表的選定值時,我得到一個空對象。RadioButtonList.SelectedValue()返回空對象

protected void Page_Load(object sender, EventArgs e) 
{ 
    q_LBL.Text = "What is the right answer?"; 
    ArrayList options = new ArrayList(); 
    options.Add("a"); 
    options.Add("b"); 
    options.Add("c"); 
    options.Add("d"); 
    options.TrimToSize(); 
    options_RBL.DataSource = options; 
    options_RBL.DataBind(); 
} 

protected void submit_BTN_Click(object sender, EventArgs e) 
{ 
    fb_LBL.Text = options_RBL.SelectedValue; 
} 

回答

1

試試這個

protected void Page_Load(object sender, EventArgs e) 
{ 
    if(!Page.IsPostBack) 
{ 
    q_LBL.Text = "What is the right answer?"; 
    ArrayList options = new ArrayList(); 
    options.Add("a"); 
    options.Add("b"); 
    options.Add("c"); 
    options.Add("d"); 
    options.TrimToSize(); 
    options_RBL.DataSource = options; 
    options_RBL.DataBind(); 

} 
} 

protected void submit_BTN_Click(object sender, EventArgs e) 
{ 
    fb_LBL.Text = options_RBL.SelectedValue; 
}