posts - 5 , comments - 1 , trackbacks - 0

My Links

News

Article Categories

Archives

Image Galleries

IIS

Sort listbox items using jQuery in ASP.Net

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

Print | posted on Friday, November 4, 2016 6:32 AM | Filed Under [ Asp.Net JavaScript jQuery ]

Feedback

No comments posted yet.
Post A Comment
Title:
Name:
Email:
Comment:
Verification:
 

Powered by: