This is a migrated thread and some comments may be shown as answers.
Filter radgrid on button click
1 Answer 103 Views
This is a migrated thread and some comments may be shown as answers.
Sir
Top achievements
Rank 1
Sir asked on 07 Oct 2012, 10:53 AM
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.


1 Answer, 1 is accepted

Sort by
0
Shinu
Top achievements
Rank 1
answered on 08 Oct 2012, 04:57 AM
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.
Tags
Grid
Asked by
Sir
Top achievements
Rank 1
Answers by
Shinu
Top achievements
Rank 1
Share this question
or