asp.net中的单选按钮和面板 [英] Radio Button and panel in asp.net

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

问题描述

Hi Friends ..

我在页面中有两个单选按钮.


当我选择第一个单选按钮时,将显示面板1.

当我选择第二个单选按钮时,将显示面板2.

我该怎么做.

Hi Friends..

I have a two radio buttons in a page.


When i am select first radio button the panel 1 will be displayed.

When i am select Second radio button the panel 2 will be displayed.

How can i do this.

<td>
                    <asp:DropDownList ID="drop" runat="server" OnSelectedIndexChanged="drop_SelectedIndexChanged"

                        AutoPostBack="True">
                        <asp:ListItem Text="Select"> </asp:ListItem>
                        <asp:ListItem Text="Full Day"> </asp:ListItem>
                        <asp:ListItem Text="Half Day"> </asp:ListItem>
                        <asp:ListItem Text="Leave"> </asp:ListItem>
                    </asp:DropDownList>
                    <asp:RadioButton ID="radio" Text="FN" runat="server" />
                    <asp:RadioButton ID="radioAN" Text="AN" runat="server" AutoPostBack="True" />
                     
                </td>

推荐答案

您已经

You have

<asp:RadioButton ID="radio" Text="FN" runat="server" AutoPostBack="True" />
                    <asp:RadioButton ID="radioAN" Text="AN" runat="server" AutoPostBack="True" />




在页面加载事件中尝试此代码将起作用,或者您可以生成RadioButton的选择更改事件




Try This Code in Page Load Event it will work or you can genrate selection changed event of RadioButton

//For Event you can write this in radio Selection changed Event
If(radio.Checked)
{
Panel1.visible=true;
}
else
{
Panel2.visible=false;
}
//For Event you can write this in radioAN Selection changed Event
If(radioAN.Checked)
{
Panel1.visible=false;
}
else
{
Panel2.visible=true;
}


首先,
将两个单选按钮的自动回发"属性设置为true.并将Visible属性False设置为两个面板.同时为两个单选按钮提供相同的组名.

然后双击第一个单选按钮....,那么您将获得单选按钮的方法.
里面....

First of all,
Set Auto Postback property true for both Radio Button. and set Visible property False to both panel. also give Groupname Same to Both Radio Button.

then Double Click on First Radio Button.... So ,you get Method of Radio Button.
Inside it....

If(RadioButton1.Checked)
{
   Panel.visible=true;
}
else
{
    Panel2.visible=false;
}



然后双击第二个单选按钮....,您将获得单选按钮的方法.
里面...



then Double Click on Second Radio Button.... So ,you get Method of Radio Button.
Inside it...

If(RadioButton2.Checked)
{
   Panel1.visible=false;
}
else
{
    Panel2.visible=true;
}


我个人会使用单选按钮列表.在selectedIndexChanged事件(onPostback)上,您可以更改面板.如果您使用了多视图控件,并且可以为每个视图ActiveIndex选择基于单选按钮列表的selectedIndex的控件,那将是一个很好的选择.
Personally I would use a radiobuttonlist. On the selectedIndexChanged event (onPostback) you could change the panel. What would work really well is if you used a mulitview control and for each view ActiveIndex you could select that based on the selectedIndex of the radiobuttonlist.


这篇关于asp.net中的单选按钮和面板的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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