Displaying different form fields based on radio button selection

  • Thread starter Thread starter lltaylor
  • Start date Start date
L

lltaylor

Hello,

I am trying to create a form which when initially displayed only has 2
radio buttons. Then based on which radio button you select the
appropriate form appears below the radio buttons.

What is the best of way of achieving this?

Can I layer the form objects?

I am relatively new to C# so any help on this matter would be
gratefully recieved.

Regards

Lloyd
 
One way to do it is to place each set of controls on it's own panel, then
simply hide and show the appropriate panel based on the radio buttons.
 
Hi,

Use a Panel WebControl to group each set of controls , and depending of
which one is selected set the Panel.Visible property accordly.

This is a similar code but using a DropDownList instead:
in the aspx code:
<asp:DropDownList Runat=server ID="SelectSectionDRP"
OnSelectedIndexChanged="ChangeSection" AutoPostBack=True></asp:DropDownList>

in the code behind:
protected void ChangeSection( object sender, System.EventArgs e)
{
if ( SelectSectionDRP.SelectedIndex == 0 )
{

CarsInvolvedPanelControls.Visible = PassengerPanel.Visible = false;
return;
}
if ( SelectSectionDRP.SelectedIndex == 1 )
CarsInvolvedPanelControls.Visible = true;
else
PassengerPanel.Visible = true;

}

//Note
CarsInvolvedPanelControls & PassengerPanel are two Panel.

Hope this help,
 
Back
Top