DataTable 排序

DataTable newdtb = new DataTable();
        newdtb.Columns.Add("Id", typeof(int));
        newdtb.Columns.Add("ProName", typeof(string));
        newdtb.Columns.Add("ProPrice", typeof(decimal));
        newdtb.Columns["Id"].AutoIncrement = true;

for (int i = 1; i < 11; i++)
        {
            DataRow newRow = newdtb.NewRow();
            newRow["ProName"] = "pro" + i.ToString();
            newRow["ProPrice"] = 12.3m;
            newdtb.Rows.Add(newRow);       
        }
       
            newdtb.DefaultView.Sort = "id ASC, ProPrice desc";
            DataTable dtTemp = dt.DefaultView.ToTable();
dtTemp 即按你需要排序的表。

 

posted on 2013-09-23 16:25  小东北  阅读(848)  评论(0编辑  收藏  举报