|With the following code, able to retrieve data source. But if we apply any filter in the grid it is returning all the data instead of filtered.
protected void RadGrid1_PreRender1(object sender, EventArgs e)
|DataSet ds = (DataSet)RadGrid1.DataSource;|
7 Answers, 1 is accepted
Unfortunately you could not get the filtered data directly from the RadGrid. The DataSource property keeps the whole data to which the RadGrid is bound. To get the filtered data you could try retrieving the filter expression from RadGrid1.MasterTableView.FilterExpression property and re-query the database. In this way, you will be able to get all the filtered data. More information about operating with the FilterExpression you could find in this documentation article.
the Telerik team
Is there is no way to fetch the filtered data? Or there is no event to get filtered data.
That GetFilteredDatasource looks very promising but when converted to VB throws an error. Does anyone out there know why the following will not compile -
Private Function GetFilteredDataSource() As DataTable
Dim DT As New DataTable()
Dim FilteredDT As New DataTable()
Dim filterexpression As String = String.Empty
filterexpression = RadGrid1.MasterTableView.FilterExpression
DT = DirectCast(RadGrid1.DataSource, DataTable)
FilteredDT = DT.AsEnumerable.AsQueryable.Where(filterexpression).CopyToDataTable
The bolded portion shows an error -
Value of type 'String' cannot be converted to 'System.Linq.Expressions.Expression(Of System.Func(Of System.Data.DataRow, Boolean))'.
Extension method 'Public Function Where(predicate As System.Func(Of System.Data.DataRow, Integer, Boolean)) As System.Collections.Generic.IEnumerable(Of System.Data.DataRow)' defined in 'System.Linq.Enumerable': Value of type 'String' cannot be converted to 'System.Func(Of System.Data.DataRow, Integer, Boolean)'.
Extension method 'Public Function Where(predicate As System.Func(Of System.Data.DataRow, Boolean)) As System.Collections.Generic.IEnumerable(Of System.Data.DataRow)' defined in 'System.Linq.Enumerable': Value of type 'String' cannot be converted to 'System.Func(Of System.Data.DataRow, Boolean)'.
Also, the grid's PageSize must be set to at least the number of filtered rows to get all the data. I set it to Int.MaxValue when filtering then rebind the grid after getting the data to return to the PageSize specified in the RadGrid markup. This is imperceptible to the user, other than perhaps a slight delay in loading the grid if the filtered dataset is very large.
ResolvedDataSourceView contains the columns with FilterExpressions and a column called "OriginalDataItem", which is a DataRowView containing all columns from the original DataSource.
This is not a fully working example, just an outline of the process involved.