Filter radgrid on button click

2 posts, 0 answers
  1. Sir
    Sir avatar
    1 posts
    Member since:
    Oct 2012

    Posted 07 Oct 2012 Link to this post

    I have a RadGrid with textbox filters which I have set to AutoPostBack = False. I've also hidden the FIlter Icon.

    I have created a button in the command row for "Apply filters". I want to use the "Apply Filters" command button to evaluate the value of the column filter textboxes and then trigger the internal filtering event for the grid.

    ie: user types into filter textboxes, then clicks "Apply Filters" which builds the FilterExpression and triggers the filtering event.

    Could you help me out with an example, I have been searching but no luck.

  2. Shinu
    Shinu avatar
    17764 posts
    Member since:
    Mar 2007

    Posted 07 Oct 2012 Link to this post


    Please take a look into the following code snippet I tried to filter RadGrid on external button click.

    <telerik:RadGrid ID="RadGrid1" runat="server" DataSourceID="SqlDataSource1" AutoGenerateColumns="false" AllowFilteringByColumn="true" EnableLinqExpressions="false">
        <MasterTableView CommandItemDisplay="Top">
                <asp:Button ID="Button1" runat="server"  Text="Filter" onclick="Button1_Click"/>
                <telerik:GridBoundColumn UniqueName="OrderID" DataField="OrderID" HeaderText="OrderID"  AutoPostBackOnFilter="false" ShowFilterIcon="false"></telerik:GridBoundColumn>
                <telerik:GridBoundColumn UniqueName="ShipCity" DataField="ShipCity" HeaderText="ShipCity"  AutoPostBackOnFilter="false" ShowFilterIcon="false"></telerik:GridBoundColumn>

    protected void Button1_Click(object sender, EventArgs e)
        GridFilteringItem filteringItem = (GridFilteringItem)RadGrid1.MasterTableView.GetItems(GridItemType.FilteringItem)[0];
        TextBox text1 = filteringItem["OrderID"].Controls[0] as TextBox;
        string filterExpression;
        filterExpression = "([OrderID] = '" + text1.Text + "')";
        RadGrid1.MasterTableView.FilterExpression = filterExpression;

Back to Top