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
Solved

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

Posted on 2006-07-17
8
708 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
  • 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
Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
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

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

I have developed many web applications with asp & asp.net and to add and use a dropdownlist was always a very simple task, but with the new asp.net, setting the value is a bit tricky and its not similar to the old traditional method. So in this a…
Problem Hi all,    While many today have fast Internet connection, there are many still who do not, or are connecting through devices with a slower connect, so light web pages and fast load times are still popular.    If your ASP.NET page …
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…

829 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