This article shows the method of C# to implement Datatable sorting, and is shared with you for your reference. The specific methods are as follows:
Generally speaking, to sort Datatables in C#, you can use the Sort method of DefaultView. You need to first get the DefaultView of Datatable, then set the sort property of the obtained Dataview, and finally use the ToTable method of the view to export the sorted dataview to Datatable.
The code is as follows:
DataTable dt = new DataTable(); ("ID", typeof(int)); ("Name", typeof(string)); (new object[] { 12, "lwolf" }); (new object[] { 100,"kkkkk"}); (new object[] { 19,"jim" }); (new object[] { 1,"test" }); DataTable dtCopy = (); DataView dv = ; = "ID"; dtCopy = ();
In this way, the final result is the sorted Dataable.
I hope this article will be helpful to everyone's C# programming.