2016年8月9日 星期二

ASP.NET DataTable Sorting c#

ASP.NET DataTable Sorting c#

DataTable dt = new DataTable();

dt.Columns.Add("Column_1", typeof (string));

dt.Columns.Add("Column_2", typeof (string));

dt.Columns.Add("Column_3", typeof (string));


dt.Rows.Add("1", "二", "C");

dt.Rows.Add("2", "三", "A");

dt.Rows.Add("3", "一", "B");

dt.DefaultView.Sort = "Column_1 DESC";

dataGridView1.DataSource = dt;

dt.DefaultView.sort = "AG DESC";

dt = dt.DefaultView.ToTable(); //將排序好的 DefaultView 產出新的DataTable 或是複寫回去。

ref:
https://social.msdn.microsoft.com/Forums/zh-TW/07dda425-e1b7-4202-8fca-31c3c31a0159/datatable-?forum=233

2 則留言:

  1. clifton@mail.postmanllc.net

    回覆刪除
  2. Thank you for your post. Hawkscode Uk is the leading IT service provider. Hawkscode Uk
    is web development company.

    回覆刪除