SpgridView过滤和使用DataTable排序
-
10-12-2019 - |
题
我需要基于DataTable的帮助过滤和排序SpGridView,从我在线看到的文章,它们使用ObjectDataSource等,但我将网格直接绑定到DataTable,是有没有关于如何实现的教程在这种情况下过滤或排序?我已经尝试了很多,现在为我工作。
感谢
解决方案
过滤
.
oGrid.AllowFiltering = true;
oGrid.FilterDataFields = "Title"; //tells the SPGridView what columns we want to be able to filter on.
oGrid.FilteredDataSourcePropertyName = "FilterExpression";
oGrid.FilteredDataSourcePropertyFormat = "{1} like '{0}'"; //property provides the format for our filter expression in a SQL-like syntax.
排序
.
oGrid.AllowSorting = true;
oGrid.Sorting += new GridViewSortEventHandler(oGrid_Sorting);
void oGrid_Sorting(object sender, GridViewSortEventArgs e)
{
// Call bind datatable function
BindData();
}
// Also make sure when you are adding the columns you should define SortExpression
BoundField colTitle = new BoundField();
colTitle.DataField = "Title";
colTitle.HeaderText = "Title";
colTitle.SortExpression = "Title";
this.oGrid.Columns.Add(colTitle);
引用