First of all, we have to refer jQuery on the page. Kindly down the latest jQuery from below url
Below is the function, will sort list box items in the ascending order
function SortListbyAscending(listname) {
var $r = $(listname + ” option”);
$r.sort(function (a, b) {
return parseInt(a.value) == parseInt(b.value) ? 0 : parseInt(a.value) < parseInt(b.value) ? -1 : 1;
});
$($r).remove();
$(listname).append($($r));
}
Pass listbox as a parameter to run the above function. My requirement is to do it on button click. Please find below how to call
$(“#btnSubmit”).bind(“click”, function () {
SortListbyAscending(“[id*=lstBoxId]”);
});
That’s it.
– Karthick Raju