单选按钮列表OnSelectedIndexChanged [英] RadioButtonList OnSelectedIndexChanged

查看:323
本文介绍了单选按钮列表OnSelectedIndexChanged的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在寻找处理指标的变化的最佳方式上ASP.net RadioButtonList的被选中(C#code后面)。我有3个列表项。对于第一个,我希望它显示隐藏的ASP:页面上的文本框,而其他2将隐藏文本框。

I'm looking for the best way to handle a change of index being selected on a ASP.net RadioButtonList (C# code behind). I have 3 list items. For the first one, I want it to show a hidden asp:textbox on the page, whereas the other 2 will hide the textbox.

//asp.net side
<asp:RadioButtonList ID="_indicatorAckType" runat="server" RepeatDirection="Horizontal"
                enabled="true" OnSelectedIndexChanged="onAckTypeChanged">
    <asp:ListItem Text="None" />
    <asp:ListItem Text="SHOW" />   
    <asp:ListItem Text="HIDE" />
</asp:RadioButtonList>

//code behind
protected void onAckTypeChanged(object sender, EventArgs e)
{
    if (_indicatorAckType.SelectedItem.Text == "SHOW")
        _myTextboxID.Visible = true;
    else
        _myTextboxID.Visible = false;
}

我最初尝试使用onclick事件处理程序,但我已经告诉列表项的不能使用的单选按钮项目的onclick事件。我在做什么错在这里?这不抛出任何错误或有任何明显的明显的问题。我试图让onSelectedIndexChanged什么都不做,除了显示文本框,并且也不管用。

I initially tried using onclick event handlers, but I've been told that ListItem's cannot use onclick events with radio button items. What am I doing wrong here? This does not throw any errors or have any visibly obvious problems. I have tried making onSelectedIndexChanged do nothing except show the textbox and that doesn't work either.

任何帮助AP preciated!谢谢大家。

Any help is appreciated! Thanks everyone.

推荐答案

在在RadioButtonList中,的AutoPostBack 属性设置为true。

On the RadioButtonList, set the AutoPostBack attribute to true.

这篇关于单选按钮列表OnSelectedIndexChanged的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆