开发者

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开发者_如何学Go text box and label will visible, else it won't be visible. So how to do this?


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.


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜