javascript - sort entries of a drop down alphabitically -


i dynamically adding drop entries drop down using following code.

var x =document.getelementbyid("x"); var optn = document.createelement("option"); optn.text="hhh";   optn.value="val";   x.add(optn);   

the above thing done in loop want sort alphabatically.how can it?

public void sortdropdownlist(dropdownlist ddl) {     //create listitem array size of items     //in dropdownlist     listitem[] sorted = new listitem[ddl.items.count];     //loop through items in listitem array     (int = 0; < sorted.length; i++)     {         //resize array on each iteration         array.resize(ref sorted, i);         //add current index array         sorted[i] = ddl.items[i];     }     //call array.sort sort listitem array     array.sort(sorted);     //remove items dropdownlist     ddl.items.clear();     //add sorted items dropdownlist     ddl.items.addrange(sorted); } 

u use of function after items bound dropdownlist


Comments

Popular posts from this blog

apache - Add omitted ? to URLs -

redirect - bbPress Forum - rewrite to wwww.mysite prohibits login -

php - How can I stop spam on my custom forum/blog? -