How to set ASP.net dropdownlist index to 0 from the front-end

前端 未结 2 1553
情话喂你
情话喂你 2021-01-29 07:25

I have the following code in ASP.net page:



        
2条回答
  •  滥情空心
    2021-01-29 07:55

    I was using the Chosen Jquery which caused the dropdownlist to not update.

    This is the HTML:

    
    

    JavaScript which sets the selected index to 0:

    function setSelectedIndex(dropdownlist, selVal) {
        var ddl1 = document.getElementById(dropdownlist);
        if (selVal < ddl1.selectedIndex) {
            ddl1.selectedIndex = selVal;
    
            $(ddl1).val(0).trigger('chosen:updated');
        }
    }
    

    That does the trick.

提交回复
热议问题