There are 2 listboxes to exchange items. Each list item has text and value properties eg: "Branch",1 ; "Leaves",23,...etc After adding an item from listbox2 to listbox1, I would like to sort listbox1.
lb1 and lb2 are the listboxes.
protected void btnRemove_Click()
{
if(lb2.Items.count > 0)
{
if(lb2.selectedindex >=0)
{
ListItem li = lb2.selecteditem;
lb1.items.add(li);
//sort
List<ListItem> al = new List<ListItem>();
foreach(listitem l in lb1.items)
{
al.Add(l);
}
lb1.items.clear();
al.sort();
lb1.Datasource=al;
lb1.databind();
}
}
}
At al.sort(); it gives an error - "Failed to compare 2 elements in the array". How should I correct this.