0

. RadioButtonList가있는 .aspx 페이지에 양식이 있습니다. ArrayList 및 BindData()를 사용하여 목록을 채 웁니다. 목록의 선택된 값을 가져 오려고하면 null 객체가 생깁니다.RadioButtonList.SelectedValue() null 객체를 반환합니다.

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; 
} 
시도
관련 문제