c # sorted according to the specified column


C # provides built-in objects DataTable is particularly strong, if we need a column in the DataTable sort how to deal with it, the specific code as follows:
DataTable dt = new new DataTable (); dt.Columns.Add ( "Id"); dt .Columns.Add ( "the Name"); dt.Rows.Add (new new Object [] {. 1, "zhangsan"}); dt.Rows.Add (new new Object [] {2, "taoge"}); dt. DefaultView.Sort = "Id DESC"; // Id by reverse dt.DefaultView.Sort = "Id DESC, Name desc "; // Name reverse and reverse by Id dt = dt.DefaultView.ToTable (); // return a new DataTable

 

Guess you like

Origin www.cnblogs.com/lypstudy/p/11563589.html