【问题标题】:RadioButtonList.SelectedValue() returning null objectRadioButtonList.SelectedValue() 返回空对象
【发布时间】:2014-12-21 03:25:03
【问题描述】:

我在带有 RadioButtonList 的 .aspx 页面上有一个表单。我使用 ArrayList 和 BindData() 填充列表。当我尝试获取列表的选定值时,我得到一个空对象。

    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;
}

【问题讨论】:

    标签: c# asp.net visual-studio-2010 data-binding radiobuttonlist


    【解决方案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;
    }
    

    【讨论】:

      猜你喜欢
      • 2014-09-29
      • 2015-02-11
      • 2020-12-21
      • 2019-04-08
      • 2012-02-22
      • 2019-07-17
      • 2018-08-03
      • 2022-01-11
      • 1970-01-01
      相关资源
      最近更新 更多