Barry Michael Doyle Barry Michael Doyle - 4 months ago 40
ASP.NET (C#) Question open DropDownList control in code-behind

I would like to have an

expand when an
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)


use javascript/Jquery to do this..Here is how you can do it

in .aspx page

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

                //Emty your dropdown list first
                //Add first option for validation
                var option = '<option value="">Select</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);
//                }

See this link link