如何从RadioButtonList获取选定的单选按钮对象

时间:2011-10-25 10:35:24

标签: asp.net

如何从SelectedIndexChanged事件中的RadioButtonList获取选定的RadioButton对象

好的更多描述

我需要捕捉radiobuttonlist中选择的radiobutton,以便在radiobuttonlist autopostback

时关注它

2 个答案:

答案 0 :(得分:1)

试试这个:

protected void rbl_SelectedIndexChanged(object sender, EventArgs e)
    {
        RadioButtonList rbList = (RadioButtonList)sender;
        ListItem selItem = rbList.Items[rbList.SelectedIndex];
        selItem.Selected = true;
    }

答案 1 :(得分:1)

void RadioButtonList1_SelectedIndexChanged(object sender, EventArgs e)
{
    var script = string.Format("document.getElementById('{0}_{1}').focus();", RadioButtonList1.ClientID, RadioButtonList1.SelectedIndex);

    if (ScriptManager.GetCurrent(this) != null && ScriptManager.GetCurrent(this).IsInAsyncPostBack)
        ScriptManager.RegisterStartupScript(RadioButtonList1, typeof(RadioButtonList), Guid.NewGuid().ToString(), script, true);
    else
        ClientScript.RegisterStartupScript(typeof(RadioButtonList), Guid.NewGuid().ToString(), script, true);
}