Asp.net在代码隐藏中打开DropDownList控件 [英] Asp.net open DropDownList control in code-behind

查看:63
本文介绍了Asp.net在代码隐藏中打开DropDownList控件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我希望< asp:DropDownList> < asp:Button> 时展开点击。
我可以在点击事件中使用哪些功能来实现这一目标?

I would like to have an <asp:DropDownList> expand when an <asp:Button> is clicked. What function can I use inside the click event to make this happen?

修改:

似乎没有功能可以做服务器端,如果我必须在客户端做,根据列表中有多少项,最好的方法是什么? (列表在按钮单击时动态填充)

It seems like there's no function to do that server-side, if I have to do it client side, what's the best way to do it according to how many items are in the list? (the list is populated dynamically on the the button click)

推荐答案

使用Javascript / JQuery执行此操作。以下是一个示例:

Use Javascript/JQuery to do this. Here's an example:

在.aspx页面

    <div>
    <asp:Button ID="btnShowDropDown" runat="server" Text="AddDropdown"  ClientIDMode="Static" />
    </div>
    <div>
        <asp:DropDownList ID="ddlTest" runat="server" ClientIDMode="Static">
          </asp:DropDownList>
    </div>
    <script>
        $(function() {
            $('#btnShowDropDown').on('click', function (e) {
                e.preventDefault();

                //Emty your dropdown list first
                $('#ddlTest').empty();
                //Add first option for validation
                var option = '<option value="">Select</option>';
                $('#ddlTest').append(option);
                //Open dropdown list for size 6
                $('#ddlTest').attr('size', 6);
                //For more add by other data ..Left for your convinent
//                for (var i = 0; i < result.d.length; i++) {
//                  
//                    option = '<option value="' + result.d[i].Id + '">' + result.d[i].SubProductName + '</option>';
//                    $('#ddlTest').append(option);
//                }
            });
        })
    </script>

请参阅链接

这篇关于Asp.net在代码隐藏中打开DropDownList控件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆