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

Filter Record onTextChanged event of internal TextBox(Header TextBox) in Radgrid

3 Answers 208 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Mayur
Top achievements
Rank 1
Mayur asked on 08 Aug 2012, 03:14 PM
Is it possible to filter records onTextChanged or onKeyUp event of internal TextBox(Header TextBox) of Radgrid?
I dont want to select 'Start With', 'Contains' and other options from dropdown to filter records in Radgrid.

Find the attached file for more understanding...

3 Answers, 1 is accepted

Sort by
0
Jayesh Goyani
Top achievements
Rank 2
answered on 08 Aug 2012, 04:27 PM
0
Mayur
Top achievements
Rank 1
answered on 14 Aug 2012, 01:32 PM
Thanks Jayesh,
But here filter operation works on enter key. I want it on text change.
 Is it possible to filter record on text change?
0
Accepted
Jayesh Goyani
Top achievements
Rank 2
answered on 14 Aug 2012, 07:28 PM
Hello,

Please check below code snippet.

<telerik:RadGrid ID="RadGrid1" runat="server" AutoGenerateColumns="False" OnItemDataBound="RadGrid1_ItemDataBound"
            OnNeedDataSource="RadGrid1_NeedDataSource" AllowPaging="true"  AllowFilteringByColumn="true" EnableLinqExpressions="false">
            <MasterTableView CommandItemDisplay="Top" DataKeyNames="ID" EditMode="InPlace">
                <CommandItemSettings ShowExportToPdfButton="true" />
                <Columns>
                    <telerik:GridBoundColumn DataField="ID" UniqueName="ID" HeaderText="ID">
                    </telerik:GridBoundColumn>
                    <telerik:GridTemplateColumn UniqueName="Name" DataField="Name">
                        <FilterTemplate>
                            <asp:TextBox ID="TextBox1" runat="server" AutoPostBack="True" OnTextChanged="TextBox1_TextChanged"></asp:TextBox>
                        </FilterTemplate>
                        <ItemTemplate>
                        <asp:Label ID="Label1" runat="server" Text='<%# Eval("Name") %>'></asp:Label>
                        </ItemTemplate>
                    </telerik:GridTemplateColumn>
                    <telerik:GridEditCommandColumn>
                    </telerik:GridEditCommandColumn>
                </Columns>
            </MasterTableView>
        </telerik:RadGrid>
protected void RadGrid1_NeedDataSource(object sender, GridNeedDataSourceEventArgs e)
       {
           dynamic data = new[] {
             new { ID = 1, Name ="aaa"},
             new { ID = 2, Name = "bbb"},
             new { ID = 3, Name = "ccc"},
             new { ID = 4, Name = "ddd"},
              new { ID = 5, Name ="eee"}
           };
           RadGrid1.DataSource = data;
       }
 
       protected void RadGrid1_ItemDataBound(object sender, GridItemEventArgs e)
       {
            
       }
 
       protected void TextBox1_TextChanged(object sender, EventArgs e)
       {
            
 
           TextBox TextBox1 = sender as TextBox;
           RadGrid1.MasterTableView.FilterExpression = "([Name] LIKE \'%" + TextBox1.Text.Trim() + "%\') ";
           GridColumn column = RadGrid1.MasterTableView.GetColumnSafe("Name");
           column.CurrentFilterFunction = GridKnownFunction.Contains;
           column.CurrentFilterValue = TextBox1.Text.Trim();
 
           RadGrid1.Rebind();
 
       }


Thanks,
Jayesh Goyani
Tags
Grid
Asked by
Mayur
Top achievements
Rank 1
Answers by
Jayesh Goyani
Top achievements
Rank 2
Mayur
Top achievements
Rank 1
Share this question
or