簡體   English   中英

RadioButtonList OnSelectedIndexChanged

[英]RadioButtonList OnSelectedIndexChanged

我正在尋找處理在ASP.net RadioButtonList(后面的C#代碼)上選擇的索引更改的最佳方法。 我有3個列表項。 對於第一個,我希望它在頁面上顯示隱藏的asp:文本框,而另外2個將隱藏文本框。

//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事件處理程序,但我被告知ListItem不能使用帶單選按鈕項的onclick事件。 我在這做錯了什么? 這不會引發任何錯誤或有任何明顯的問題。 我已經嘗試使onSelectedIndexChanged除了顯示文本框之外什么都不做,但也不起作用。

任何幫助表示贊賞! 感謝大家。

在RadioButtonList上,將AutoPostBack屬性設置為true。

看看這可能會有所幫助。 我建議關閉autopostback如果在單選按鈕上啟用,請在客戶端使用jquery完成所有操作。

例:

使用jQuery,如果選擇了單選按鈕,則隱藏文本框

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM