28 December, 2009
3 Comments
0 categories
If you want to set an initial filter on a Telerik RadGrid, use the “NeedDataSource” event and set the MasterTableView.FilterExpression and use the function MasterTableView.GetColumnSafe
protected void RadGrid_NeedDataSource(object source, GridNeedDataSourceEventArgs e) { // Set datasource here… if (!IsPostBack) { // Set initial filter on [RadGrid] this.RadGrid.MasterTableView.FilterExpression = string.Format("([Date] = '{0}')", DateTime.Today); // Set current filter function and value on [Date] GridColumn column = this.RadGrid.MasterTableView.GetColumnSafe("Date"); column.CurrentFilterFunction = GridKnownFunction.EqualTo; column.CurrentFilterValue = DateTime.Today.ToString(); } }
In the aspx page use “EqualTo” as filter, not “Contains” and use a GridDateTimeColumn not a GridBoundColumn
<telerik:GridDateTimeColumn DataField="Date" HeaderText="Date" SortExpression="Date" UniqueName="Date" FilterControlWidth="70px" ShowFilterIcon="false" DataType="System.DateTime" CurrentFilterFunction="EqualTo" PickerType="DatePicker" AutoPostBackOnFilter="true" HtmlEncode="false" DataFormatString="{0:dd-MM-yyyy}" meta:resourcekey="Date"> <ItemStyle Width="70px" /> </telerik:GridDateTimeColumn>
Tags: Telerik
Nice post. Were you able to filter on muliple columns?
Yes you can filter on multipe columns, maybe this week I will create a new blog post.
I am doing the same but not able to filter the grid on load.
Please tell if we need to do anything extra.