Hi
I want to use the selected row filter in my sql query.
I have a Grid which is setup to use row filtering. e.Layout.FilterOptionsDefault.AllowRowFiltering = RowFiltering.OnServer; e.Layout.FilterOptionsDefault.FilterUIType = FilterUIType.FilterRow;
I want to to use this filter, when getting data from the base
UltraWebGridAlarms_InitializeDataSource {
string where = ""; foreach (ColumnFilter cf in UltraWebGridAlarms.Rows.ColumnFilters) { if (string.IsNullOrEmpty(where)) { where = string.Format("{0}='{1}'", cf.Column.Key, cf.FilterConditions[0].CompareValue); } else { where = string.Format(" and {0}='{1}'", cf.Column.Key, cf.FilterConditions[0].CompareValue); } }
UltraWebGridAlarms.DataSource = alarmController.getAlarms(where); UltraWebGridAlarms.DataBind(); }
My problem is that the UltraWebGridAlarms.Rows.ColumnFiltersis empty in UltraWebGridAlarms_InitializeDataSource method.
In the method UltraWebGridAlarms_RowFilterApplying, I get access to the UltraWebGridAlarms.Rows.ColumnFilters.
Any suggestion to how I should apply the seleced row filter in my sql query?
InitializeDataSource is fired when grid.DataBind is called. So the first thing I would recommend, is remove the call to DataBind from inside of the InitializeDataSource event.
Next, I like to do my manual filtering on the DataSource, not on the grid. Add an eventhandler to your datasource's Selecting or DataBinding event, and work the Where clause out there. You can be certain that if the datasource is being asked for data - the grid has requested it.
One other tidbit - the grid like's to databind 2 times. The first time it gets the "original" data so that it can compare it to any changes that were made on the client-side. The second time the grid databinds it's to get the most up to date data. If you set the EnableInternalRowsManagement property to true, the grid will use ViewState to store the 'original' data in.
-Tony
Thanks for your tips about DataBind.
I have tried the _Selecting event on a DataSource. Here are my results:
When using Pageing: If I sets a filter in the grid, the _Selecting event i fired twice. The second time is the property UltraWebGridAlarms.DisplayLayout.Rows.HasColumnFilters true, and I can use .Rows.ColumnFilters to find the row filter. And use it in my sql query. (Since the first event do not have information about the filter, I have to do a sql query with out filter first)
When not using Paging: If I sets a filter in the grid, the _Seelcting event i is fired once, and UltraWebGridAlarms.DisplayLayout.Rows.HasColumnFilters is false. And I have no posiblity to get the row filter.
So I can still not use the row in my sql query.
Do you have any other suggestions to how I can catch the row filter, befor doing my sql query?