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

Filtering on auto-generated columns on page load

1 Answer 136 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Johnathan
Top achievements
Rank 1
Johnathan asked on 27 Nov 2012, 05:51 PM
Is it possible to filter auto-generated columns on page load? If so, does anyone have an example of this?

Thanks,

Johnathan

1 Answer, 1 is accepted

Sort by
0
Shinu
Top achievements
Rank 2
answered on 28 Nov 2012, 04:20 AM
Hi Jonathan,

Please take a look into the following code snippet I tried to do filter on page load.

ASPX:
<telerik:RadGrid ID="RadGrid1" runat="server" AllowFilteringByColumn="True" EnableLinqExpressions="false"
    AutoGenerateColumns="true" DataSourceID="SqlDataSource1" OnPreRender="RadGrid1_PreRender">
</telerik:RadGrid>
<asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:NorthwindConnectionString %>"
    SelectCommand="SELECT * FROM [Customers]" />

C#:
protected void RadGrid1_PreRender(object sender, EventArgs e)
{
    if (!Page.IsPostBack)
    {          
        GridColumn column = RadGrid1.MasterTableView.GetColumnSafe("Country");
        column.CurrentFilterFunction = GridKnownFunction.Contains;
        column.CurrentFilterValue = "Germany";
        RadGrid1.MasterTableView.FilterExpression = "([Country] LIKE \'%Germany%\') ";
        RadGrid1.MasterTableView.Rebind();
    }
}

Thanks,
Shinu.
Tags
Grid
Asked by
Johnathan
Top achievements
Rank 1
Answers by
Shinu
Top achievements
Rank 2
Share this question
or