Solved

.NET 2.0 C# VS make dropdownlist visible/invisible via radio button control (client side)

Posted on 2006-07-17
8
709 Views
Last Modified: 2010-08-05
I have a radiobuttonlist with 2 choices,  "car" or "truck".

If "car" is selected, I want 2 different dropdownlists (dd1 and dd2) to appear!

However if " truck" is selected, I want dropdownlist (dd3) to appear and dd1 and dd2 to disappear.

The opposite is true if "car" is selected, dd3 will disappear and dd1 and dd2 will appear again.

When the web page first appears,  dd1, dd2 and dd3 dropdownlists are all invisible and radiobuttonlist is not selected ?

Need something simple.

Thanks for help here.
0
Comment
Question by:RSSIAdmin
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 2
  • 2
8 Comments
 
LVL 7

Assisted Solution

by:whityum
whityum earned 250 total points
ID: 17123009
turn on autopostback for the rbl, have a function for onselectedindexchanged, and say
if(rbl.SelectedValue == "car"){
dd1.Visible = true;
dd2.Visible = true;
dd3.Visible = false;
}else{
dd1.Visible = false;
dd2.Visible = false;
dd3.Visible = true;
}
0
 
LVL 7

Expert Comment

by:whityum
ID: 17123018
also have visible = false in the tag on the aspx page.
0
 
LVL 35

Accepted Solution

by:
mrichmon earned 250 total points
ID: 17123604
Well the above while simple, is not user freidnly as it submits the page each time the user changes a radio button, so then you have to deal with scroll isuues, etc.

Better is to have all have the Visible=true and allow javascript to select which show up on the screen.

The javascript would look like:

function updateDDLs()
{
    if(rbl[0].checked)
    {
        dd1.style= "";
        dd2.style= "";
        dd3.style= "display:none;";
     }
    else if(rbl[1].checked)
    {
        dd1.style= "display:none;";
        dd2.style= "display:none;";
        dd3.style= "";
     }
   else
    {
        dd1.style= "display:none;";
        dd2.style= "display:none;";
        dd3.style= "display:none;";
     }
}

Then the drpdowns look need to start out with style="display: none;" and need an onChange="updateDDLs();" attribute.

Then it will dynamically update without submitting/reloading the page each time the user makes a change.
0
Creating Instructional Tutorials  

For Any Use & On Any Platform

Contextual Guidance at the moment of need helps your employees/users adopt software o& achieve even the most complex tasks instantly. Boost knowledge retention, software adoption & employee engagement with easy solution.

 
LVL 7

Expert Comment

by:whityum
ID: 17130365
he will have to get the client IDs of the drop downs if he does it that way.
0
 

Author Comment

by:RSSIAdmin
ID: 17130422
mrichmon ---

Thanks so much for the input. (both look good!)  The Javascript would save round trips

Does above show all the code I will need to get this  to work. For example do I need some kind of pointer or  reference  to rb1[0] and rb2 etc.  like form.document.rb1.. etc  ?  what is style?

function updateDDLs()
{
    if(rbl[0].checked)
    {
        dd1.style= "";
        dd2.style= "";
        dd3.style= "display:none;";
     }


Help, Tom
0
 
LVL 7

Expert Comment

by:whityum
ID: 17130553
.Net assigns an ID you can access via the ClientID property, e.g. rbl.ClientID.ToString()

you would have to build the javascript string dynamically, like
string s = "if(document.form[0]." + rbl.ClientID.ToString() + ".checked == true){";
s += "{";
s += "document.form[0]." + dd1.ClientID.ToString() + ".style = 'display: inline';"
....

and register the script to the page




0
 
LVL 35

Expert Comment

by:mrichmon
ID: 17130877
Yes.

It would be

document.getElementById("rbl")[0].checked
for the radio button.

Basically you use document.getElementById("ID of control")

This works for the ID you assign from the asp page as long as it is not repeated in a repeater.
0
 

Author Comment

by:RSSIAdmin
ID: 17137990

Thanks so much for the answer to my questions.

Tom
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

In .NET 2.0, Microsoft introduced the Web Site.  This was the default way to create a web Project in Visual Studio 2005.  In Visual Studio 2008, the Web Application has been restored as the default web Project in Visual Studio/.NET 3.x The Web Si…
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an antispam), the admini…

726 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question