2010-07-19 77 views

回答

0

用動態where子句在查詢級解決它。

1

如何排序使用.DefaultView?以下是grd_Sorting事件。

DataView dv = dt.DefaultView;//Your datatable, dt. 
dv.RowFilter = "";//Set row filter to none. 
if ((strSortBy != null) && (strSortAscending != null)) 
    dv.Sort = strSortBy/*Column name*/ + " " + strSortAscending /*ASC, for instance.*/; 

grd.DataSource = dv; 
grd.DataBind(); 
+0

嗨,我的對象數據源返回具有自定義業務對象的列表。這個解決方案是否適用於此?我也是使用自定義分頁數據(如每gridview的第10個對象) – 2010-07-19 07:27:28

+0

@Popo:在這種情況下,我會實現我的自定義對象的IComparable的。見http://www.switchonthecode.com/tutorials/csharp-snippet-tutorial-custom-list-sorting – 2010-07-19 07:59:29

+0

感謝您的答覆。但是,這意味着只對數據庫中的10條記錄進行排序,而不是對數據庫中的所有記錄進行排序(查詢只對每個gridview頁面提取10行,因此對它們進行排序並不是我所期待的)。我認爲它只能在數據庫級別上使用。 – 2010-07-19 10:11:23