在绑定到网格之前在DataTable中排序列

时间:2013-04-30 07:08:31

标签: c#

我有这段代码:

ProductRanges_Grd.DataSource = 
    ProductRangesDt.DefaultView.ToTable(true, "PROVIDER_ID", "PROVIDER_NAME");

在绑定我的网格之前,我可以通过PROVIDER_NAME订购吗?我该怎么做呢?

2 个答案:

答案 0 :(得分:4)

 // Create DataView
DataView view = myDataTable.defaultview;
// Sort by PROVIDER_ID and PROVIDER_NAME column in descending order
view.Sort = "PROVIDER_ID ASC, PROVIDER_NAME ASC";
ProductRanges_Grd.DataSource = view.ToTable();

答案 1 :(得分:0)

    myDataTable.DefaultView.Sort = "PROVIDER_NAME ASC"; 
    ProductRanges_Grd.DataSource = myDataTable;
    ProductRanges_Grd.DataBind();