I have a List object that includes 3 items: Partial, Full To H, and Full To O.
I'm binding this list to an asp OptionButtonList, and it's sorting it in alphabetical order. However, I want to sort the list like the following:
Full To H, Partial, Full To O.
How can I accomplish this?
You can also create your own custom list, and use them to sort or fill. For example, if you want to sort or fill by the following lists, you'll need to create a custom list, since there is no natural order. A custom list can correspond to a cell range, or you can enter the list in the Custom Lists dialog box.
When lists of values are displayed in an application page, a user can sort the list by clicking on the column headers. The sort order of the rows will be determined by the sort order of the values in the selected column.
Custom Sorting With key= For example with a list of strings, specifying key=len (the built in len() function) sorts the strings by length, from shortest to longest. The sort calls len() for each string to get the list of proxy length values, and then sorts with those proxy values.
In a PivotTable, click the small arrow next to Row Labels and Column Labels cells. Click a field in the row or column you want to sort. on Row Labels or Column Labels, and then click the sort option you want. To sort data in ascending or descending order, click Sort A to Z or Sort Z to A.
Linq is great for this. You could even build the order sequence up to have it defined on the fly since the execution of the sort is not executed until the ToList
.
var sortedList = yourList.OrderBy(i => i.FullToH).
ThenBy(i => i.Partial).
ThenBy(i => i.FullToO).ToList();
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With