Solved

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

Posted on 2006-07-17
8
705 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
 
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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
ASP:DataGrid and how to bind to a BoundColumn 8 38
ASP.net VB.net Load contents of a GridView  to Excel 2 27
What .NET URL re-routing tool did I use? 2 36
Server Error 11 47
In this Article, I will provide a few tips in problem and solution manner. Opening an ASPX page in Visual studio 2003 is very slow. To make it fast, please do follow below steps:   Open the Solution/Project. Right click the ASPX file to b…
In an ASP.NET application, I faced some technical problems. In this article, I list them out and show the solutions that I found.  I hope it will be useful. Problem: After closing a pop-up window, the parent page should be refreshed automaticall…
Migrating to Microsoft Office 365 is becoming increasingly popular for organizations both large and small. If you have made the leap to Microsoft’s cloud platform, you know that you will need to create a corporate email signature for your Office 365…
Learn how to create flexible layouts using relative units in CSS.  New relative units added in CSS3 include vw(viewports width), vh(viewports height), vmin(minimum of viewports height and width), and vmax (maximum of viewports height and width).

910 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

Need Help in Real-Time?

Connect with top rated Experts

23 Experts available now in Live!

Get 1:1 Help Now