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

发布于 2024-12-11 22:37:46 字数 136 浏览 0 评论 0原文

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

好吧,为了获得更多描述,

我需要捕获在单选按钮列表中选择的单选按钮,以便在单选按钮列表自动回发时关注它

How To Get The Selected RadioButton Object From The RadioButtonList in the Event of SelectedIndexChanged ??

Well for more description

i need to catch the radiobutton selected in the radiobuttonlist to focus on it when the radiobuttonlist autopostback

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

蝶舞 2024-12-18 22:37:46
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);
}
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);
}
安穩 2024-12-18 22:37:46

试试这个:

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

try this:

protected void rbl_SelectedIndexChanged(object sender, EventArgs e)
    {
        RadioButtonList rbList = (RadioButtonList)sender;
        ListItem selItem = rbList.Items[rbList.SelectedIndex];
        selItem.Selected = true;
    }
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文