views:

31

answers:

2

Hi friends, I'm having a dropdown list in my web page. And it contains two lists. 1. Yes 2.No. If we select yes then the desired text box and label will visible, else it won't be visible. So hw to do this?

+2  A: 

You can use javascript to do this. Something like

<script type="text/javascript">        
        function ChangeSel(val)
        {
            var tYes = document.getElementById("txtYes");

            if ( val === "1" )
            {
                tYes.style.display = "inline";
            }
            else
            {
                tYes.style.display = "none";
            }
        }        
    </script>

<select id="sel1" onchange="ChangeSel(this.value);">
            <option value="1">Yes</option>
            <option value="2">No</option>
        </select>

<input type="text" id="txtYes" value="" />

See a working demo.

rahul
I was about to type this :D Great answer!
PieterG
+1  A: 

You can do this using a post to the server side. Note that they use a button to hide the dropdown instead of the other way around, but the concept is the same.

Or you can do this using javascript. Basically you add a javascript function the the ASP:DropDownList's OnChange event.

Also see the tutorials at The official ASP.Net Tutorial Site.

kervin