10

我有一个名为foldername,的列的数据表documentname。数据如下:

FolderName  DocumentName
Folder1     HR[D] Document
Folder1     ___----'
Folder1     Asp_example.pdf
Folder2     SD
Folder3     Heavy_weight
Folder3     Accesorial Services

如何alphabetically.Net Framework 2.0.

我们尝试的解决方案如下,但由于它包含超过 1200000 条记录而花费了太多时间。

int counter=0;

while (counter < searchDT.Rows.Count){
   string FolderName = Convert.ToString(searchDT.Rows[counter]["Folder Name"]);

   string exp = "[Folder Name] like '" + FolderName + "'";

   if (FolderName.Contains("%") || FolderName.Contains("_") || FolderName.Contains("[]") ||      FolderName.Contains("'"))

      exp = "[Folder Name] like '" + EscapeLikeValue(FolderName) + "'";

   string sortExpression = "[Document Name] ASC";

   DataRow[] drfoldername = searchDT.Select(exp, sortExpression);

   foreach (DataRow row in drfoldername)
     drfoldernameDT.ImportRow(row);

   counter += drfoldername.Length;

 }
4

5 回答 5

41
DataTable dt = new DataTable();

DataView dv = new DataView(dt);
dv.Sort = "FolderName, DocumentName ASC";

试试看。它将首先对 进行排序FolderName,然后对 进行排序DocumentName

如果您需要将其发送到屏幕上的组件,您可以像使用DataTable.

于 2012-12-27T09:29:33.450 回答
3

Here was my solution to this problem:

Datatable FI = new Datatable();
DataView viewFI = new DataView(FI);
viewFI.Sort = "ServiceDate, ServiceRoute";
DataTable OFI= viewFI.ToTable();
于 2016-10-06T15:45:28.380 回答
2

你试过 DataView.Sort 吗?

dt.DefaultView.RowFilter = "FolderName , DocumentName ASC";
dt = dt.DefaultView.ToTable();
于 2012-12-27T09:28:50.240 回答
0

如果您使用数据表绑定 dgv,则可以使用以下操作:

数据表 dtable = (DataTable) dgv.DataSource; dtable.DefaultView.Sort =

或者检查这个:

http://www.codeproject.com/csharp/datagridsort.asp

谢谢

于 2012-12-27T11:21:00.133 回答
0

您可以使用

oDataSet.Tables[0].DefaultView.Sort = "Column1 ASC ";
于 2017-01-25T12:41:41.277 回答