S.Siva
S.Siva

Reputation: 2091

Drop down list in ASP.NET

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 how to do this?

Upvotes: 0

Views: 866

Answers (2)

kervin
kervin

Reputation: 11858

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.

Upvotes: 1

rahul
rahul

Reputation: 187040

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.

Upvotes: 2

Related Questions