如果单击radiobutton,ASP显示面板

时间:2016-04-18 07:22:41

标签: asp.net

我想向小组展示' keuze'如果我点击其中一个单选按钮。 这是我已经安抚的代码,我已经尝试了一个多小时才能让它工作。但我真的找不到解决方案,所以如果有人可以提供帮助,我会非常感激。

   <div id="object" style="position:absolute; top:300px;">
        <label>Kies een object:</label>
        <br />
        <asp:RadioButtonList ID="rblObject" runat="server" Height="52px" OnSelectedIndexChanged="rblObject_SelectedIndexChanged">
            <asp:ListItem Value="rblVloer">Vloer</asp:ListItem>
            <asp:ListItem Value="rblKamer">Kamer</asp:ListItem>
        </asp:RadioButtonList>
    </div>
        <asp:Panel ID="keuze" runat="server" style="position:absolute; top:400px;">
            <asp:Label ID="Label2" runat="server" Text="Maak je keuze:"></asp:Label>
        <asp:RadioButtonList ID="RadioButtonList2" runat="server">
            <asp:ListItem Value="rblVierkant">Vierkant</asp:ListItem>
            <asp:ListItem Value="rblKubus">Kubus</asp:ListItem>
        </asp:RadioButtonList>
        </asp:Panel>

Ander这里是radiobuttons的代码

public partial class _Default : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        keuze.Visible = false;
    }

    protected void rblObject_SelectedIndexChanged(object sender, EventArgs e)
    {
        if(rblObject.SelectedItem.Value == "rblVloer")
        {
            keuze.Visible = true;
        }
    }
}

谢谢你的时间!

1 个答案:

答案 0 :(得分:0)

我认为你需要这样的东西。我是通过jQuery完成的。

 <script src="../js/jquery.js" type="text/javascript"></script>
    <script type="text/javascript">
        $(function () {
            $('#rblObject input').click(function () {
                var selectedValue = $("#rblObject input:radio:checked").val();
                alert('Selected Value: ' + selectedValue);
                if (selectedValue == "rblVloer") {

                $("#keuze").css({ display: "none" });
                } else {
                $("#keuze").css({ display: "" });
                }

            });

        });
    </script>

<div id="object" style="position:absolute; top:300px;">
        <label>Kies een object:</label>
        <br />
        OnSelectedIndexChanged="rblObject_SelectedIndexChanged"
        <asp:RadioButtonList ID="rblObject" runat="server" Height="52px" ClientIDMode="Static">
            <asp:ListItem Value="rblVloer">Vloer</asp:ListItem>
            <asp:ListItem Value="rblKamer">Kamer</asp:ListItem>
        </asp:RadioButtonList>
    </div>
        <asp:Panel ID="keuze" runat="server" style="position:absolute; top:400px;" ClientIDMode="Static">
            <asp:Label ID="Label2" runat="server" Text="Maak je keuze:"></asp:Label>
        <asp:RadioButtonList ID="RadioButtonList2" runat="server">
            <asp:ListItem Value="rblVierkant">Vierkant</asp:ListItem>
            <asp:ListItem Value="rblKubus">Kubus</asp:ListItem>
        </asp:RadioButtonList>
        </asp:Panel>

注意:无需回发

ClientIDMode="Static"

必须获得Control的确切ID。

确保加载jQuery以执行此操作。

相关问题