How can I add option groups in ASP.NET drop down list?

后端 未结 10 1166
遇见更好的自我
遇见更好的自我 2020-11-28 10:22

I have a requirement of grouping the drop down list options in ASP.NET drop down server control. Do you have any idea to how to approach the issue? I am new to ASP.NET.

10条回答
  •  自闭症患者
    2020-11-28 11:12

    this little improvement to the client side of mhu's excellent solution also works if there are more than one select tags.

    With his version, indeed, each select tag gets filled with one copy of each option tag of each select tag

    (in this example, .select2 is the class in common to all the select tags)

    function filterUserGroups()
    {
    
        var groups = {};
        $("select option[data-category]").each(function () {
            var sGroup = $.trim($(this).attr("data-category"));
            groups[sGroup] = true;
        });
        $.each(groups, function (c) {
    
            $(".select2").each(function () {
    
                $(this).find("option[data-category='" + c + "']").wrapAll('');
    
            })
    
        });
    
    }
    

提交回复
热议问题