动态添加radiobutton的属性

时间:2011-08-02 10:15:04

标签: asp.net

我有一个带有3个radiobuttons和文本框的用户控件。如果选择RB1,我将显示文本框。对于剩下的两个选项,我将隐藏文本框。

    <asp:RadioButton ID="rbAPL" runat="server" Checked="true" CssClass="tablecelldata"
                GroupName="ServiceType" Text="Testing of Animal Pathogens & Veterinary Biologics" /><br />
    <asp:RadioButton ID="rbVPHL" runat="server" CssClass="tablecelldata" GroupName="ServiceType"
                Text="Food Testing and Export Health Certification (Veterinary Health Certificate for Meat, Fish & Dairy Products)"  /><br />
    <asp:RadioButton ID="rbPHL" runat="server" CssClass="tablecelldata" GroupName="ServiceType"
                Text="Plant Health Diagnosis Services" />

和文本框

    <asp:TextBox ID="tbxApplicationRefNo" runat="server" Width="350px"></asp:TextBox>

我想动态设置radiobuttons的属性来显示或隐藏文本框。我怎么能这样做?

预先感谢您的回复!

2 个答案:

答案 0 :(得分:0)

我会在后面的代码中做这样的事情:

public void rbAPL_CheckedChanged(object sender, EventArgs e)
{
    RadioButton button = sender as RadioButton;

    if (button.Checked)
    {
        tbxApplicationRefNo.Visible = true;
    }
}

单击时将文本框设置为可见。

答案 1 :(得分:0)

1将处理程序添加到radiobutton的js-onclick事件

2使用jquery显示/隐藏(例如:“$('#id')。show();”)

3最初注意TextBox是隐形的cos RB1是cheked

<asp:RadioButton ID="rbAPL" runat="server"  Checked="true" CssClass="tablecelldata" GroupName="ServiceType" Text="Testing of Animal Pathogens & Veterinary Biologics" onclick='<%# string.Format("$(&#39;#{0}&#39;).hide();", tbxApplicationRefNo.ClientID) %>' />
<br />
<asp:RadioButton ID="rbVPHL" runat="server" CssClass="tablecelldata" GroupName="ServiceType" Text="Food Testing and Export Health Certification (Veterinary Health Certificate for Meat, Fish & Dairy Products)" onclick='<%# string.Format("$(&#39;#{0}&#39;).show();", tbxApplicationRefNo.ClientID) %>' />
<br />
<asp:RadioButton ID="rbPHL" runat="server" CssClass="tablecelldata" GroupName="ServiceType" Text="Plant Health Diagnosis Services" onclick='<%# string.Format("$(&#39;#{0}&#39;).show();", tbxApplicationRefNo.ClientID) %>' />
<br />
<asp:TextBox style="display:none" ID="tbxApplicationRefNo" runat="server" Width="350px" Text="hello :)"></asp:TextBox>