This is a migrated thread and some comments may be shown as answers.

[Solved] Data Grid Filtering Programmatically

3 Answers 207 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Steve
Top achievements
Rank 1
Steve asked on 11 Aug 2008, 03:22 PM

Quick Question: I've added filtering to a check box column during pre rendering of the grid as described in the "Applying default filter on initial load" artical at http://www.telerik.com/help/aspnet/grid/grdapplyingdefaultfilteroninitialload.html.

This adds the filtering option but doesn't apply the filter. How can I apply the programitic filter each time the grid is databound? This will also have to allow the user to specify filtering on the other columns.

Thanks in advance,

Steve

3 Answers, 1 is accepted

Sort by
0
Princy
Top achievements
Rank 2
answered on 12 Aug 2008, 06:48 AM
Hello Steve,

I tried the same scenario at my end and its working perfect, i.e., filter is being applied to the CheckBoxColumn and also other columns can be filtered. Can you check if you have set the DataType of the CheckBoxColumn-DataField to Bit in the DataBase.
Also take a look at the code I tried out and check for differences, if any.

aspx:
 <MasterTableView AllowFilteringByColumn="true"
      <Columns> 
        <telerik:GridBoundColumn DataField="FirstName" UniqueName="FirstName"></telerik:GridBoundColumn> 
        <telerik:GridCheckBoxColumn DataField="ToandFro" UniqueName="ToandFro"></telerik:GridCheckBoxColumn> 
      </Columns> 
 </MasterTableView> 

cs:
 protected void RadGrid1_PreRender(object sender, EventArgs e) 
    { 
        if (!Page.IsPostBack) 
        { 
            RadGrid1.MasterTableView.FilterExpression = "([ToandFro] = True) "
 
            GridColumn column = RadGrid1.MasterTableView.GetColumnSafe("ToandFro"); 
            column.CurrentFilterFunction = GridKnownFunction.EqualTo; 
            column.CurrentFilterValue = "True"
 
            RadGrid1.MasterTableView.Rebind(); 
        } 
    } 

Thanks
Princy.

0
Steve
Top achievements
Rank 1
answered on 12 Aug 2008, 07:59 AM
Thanks for your reply...

The code looks the same but doesn't seem to work as I require. The filter is being added to the grid but is only applied when I click the filter button for the column. I need the grid to always filter on the grid at all times.

Thanks for your info,

Steve
0
Rebecca Scully
Top achievements
Rank 1
answered on 16 Apr 2009, 08:34 AM
I'm getting the same. I have applied a default filter in the PreRender of the grid, Rebind, and although the filter value appears when the grid loads, the filter has clearly not been applied.

Any ideas??
Tags
Grid
Asked by
Steve
Top achievements
Rank 1
Answers by
Princy
Top achievements
Rank 2
Steve
Top achievements
Rank 1
Rebecca Scully
Top achievements
Rank 1
Share this question
or