Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
95
Use Row filter in sql query
posted

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.ColumnFilters
is 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?

Parents
  • 19308
    posted

    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

Reply Children
No Data