Question

I need a help filtering and sorting SPGridView based on DataTable, from the articles I've seen online, they use ObjectDataSource and so on, but I have the Grid binded directly to DataTable, is there any tutorial on how to implement the filtering or the sorting in this case? I've tried a lot and now working for me.

Thanks

Was it helpful?

Solution

Filtering

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.

Sorting

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);

References

SP GridView Filtering in share point 2010

SPGridView All - Grouping, Paging, Filtering, Sorting

Creation of a SPGridview Webpart having Pagination, Sorting, Filtering Functionalities in Sharepoint Site in Step by Step Manner

Licensed under: CC-BY-SA with attribution
Not affiliated with sharepoint.stackexchange
scroll top