使用StartsWith排序
List<string> list = new List<string>();
DataTable dt = OrdersBll.GetDescrlineChart(" 1=1 and Company_Id='"+Company_Id+"' and Flag=0").Tables[0];
for (int i = 0; i < dt.Rows.Count; i++)
{
list.Add(dt.Rows[i]["Column1"].ToString());
}
var sortEnd= Custom_sort.sort(list);
// string str = JsonConvert.SerializeObject(sortEnd);
JavaScriptSerializer js = new JavaScriptSerializer();
string data_=js.Serialize(new { sort = sortEnd });
context.Response.Clear();
context.Response.Write(data_);
context.Response.End();
//吧数据放到list集合里 然后调用Custom_sort类里的方法 传一个集合进入
public static List<string> sort(List<string> sort) {
var result = new List<string>();
var strs = new[] {"SP","SU","FU","HO"};
foreach (var start in strs)
{
var temp = sort.Where(p => p.StartsWith(start)).OrderBy(p => p);
result.AddRange(temp);
}
result=result.OrderBy(p => p.Substring(p.Length - 2, 2)).ToList();
return result;
}//集合内写了一个这样的方法