Solved

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

Posted on 2006-07-17
8
707 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
PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

 
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

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

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

Suggested Solutions

I recently went through the process of creating a Calendar Control of events with the basis of using a database to keep track of the dates that are selectable, one requirement was to have the selected date pop-up in a simple lightbox.  At first this…
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…
In a recent question (https://www.experts-exchange.com/questions/28997919/Pagination-in-Adobe-Acrobat.html) here at Experts Exchange, a member asked how to add page numbers to a PDF file using Adobe Acrobat XI Pro. This short video Micro Tutorial sh…
This video shows how to quickly and easily add an email signature for all users on Exchange 2016. The resulting signature is applied on a server level by Exchange Online. The email signature template has been downloaded from: www.mail-signatures…

770 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