If the data is to be ordered using
C# with LINQ
then following procedure can be used
var orderedCartonData = cartonData.AsEnumerable()
.OrderBy (d => d.Field<string>("Carton").Split('-')
.Aggregate ("", (x,y) => x.PadLeft(5,'0') + y.PadLeft(5,'0')));
List<string> data = new List<string>(){
"1-11","1-14","1-5","15-19","20-30","2-2",
"31-31","5-4","5-4","5-4","5-4","5-4","6-5" };
var orderedData = data.OrderBy (d => d.Split('-')
.Aggregate ("",(x,y) => x.PadLeft(5,'0')+y.PadLeft(5,'0')));
The main point here is that, to
Sort
the items as 1-5, 1-14, 2-2, even if we split these in to two separate data items, still 14 will come first before 5 when sorted as text. To overcome this the data can be prefixed with 0s like
0000100005, 0000100014, 0000200002
as shown in the above query.