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

    Hi,

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

    ASPX:
    <telerik:RadGrid ID="RadGrid1" runat="server" DataSourceID="SqlDataSource1" AutoGenerateColumns="false" AllowFilteringByColumn="true" EnableLinqExpressions="false">
        <MasterTableView CommandItemDisplay="Top">
            <CommandItemTemplate>
                <asp:Button ID="Button1" runat="server"  Text="Filter" onclick="Button1_Click"/>
            </CommandItemTemplate>
            <Columns>
                <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>
            </Columns>
        </MasterTableView>
    </telerik:RadGrid>

    C#:
    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;
        RadGrid1.MasterTableView.Rebind();         
    }

    Thanks,
    Shinu.
  3. UI for ASP.NET Ajax is Ready for VS 2017
Back to Top