RadTextBox text after rebind

2 posts, 0 answers
  1. Fenris
    Fenris avatar
    4 posts
    Member since:
    Feb 2015

    Posted 18 Feb 2015 Link to this post

    My Grid has a RadTextBox that is being used to filter on all the columns. It Looks like this:


    <telerik:RadGrid runat="server" ID="grid1" GridLines="None" ShowFooter="False" Culture="de-DE">
        <MasterTableView AutoGenerateColumns="False" AllowMultiColumnSorting="True" CommandItemDisplay="Top">
            <CommandItemTemplate>
                <telerik:RadToolBar ID="radToolBar" Skin="Windows7" runat="server" AutoPostBack="true" Width="100%">
                    <Items>
                        <telerik:RadToolBarButton Value="section2">
                            <ItemTemplate>
                                <telerik:RadTextBox ID="textbox1" runat="server" Skin="Windows7"><ClientEvents OnKeyPress="OnKeyPress" /></telerik:RadTextBox>
                                <telerik:RadButton ID="btnSearch" runat="server" Skin="Windows7" Text="Search" CommandName="Search" OnClick="searchButton_Click"/>
                            </ItemTemplate>
                        </telerik:RadToolBarButton>
                    </Items>
                </telerik:RadToolBar>
            </CommandItemTemplate>
        </MasterTableView>
        <GroupingSettings CaseSensitive="False" />
    </telerik:RadGrid>


    Now when I click the button to do the filtering, this function gets called.

    protected void searchButton_Click(object sender, EventArgs e)
    {
        RadTextBox searchFilter = GetSearchBox();
        if (searchFilter == null) return;
     
        var filterExpression = new StringBuilder();
        var searchText = searchFilter.Text;
        foreach (GridColumn col in grid1.MasterTableView.Columns)
        {
            filterExpression.AppendFormat("{0}(it[\"{1}\"].ToString().ToUpper().Contains(\"{2}\".ToUpper()))",
                filterExpression.Length != 0 ? " OR " : string.Empty, col.UniqueName, searchText);
        }
     
        activePassiveGrid.MasterTableView.FilterExpression = filterExpression.ToString();
        activePassiveGrid.MasterTableView.Rebind();
    }


    This works as expected. But after the Rebind(), the filtering becomes active, which clears the text in my textbox. I don't want it to be cleared, so you can still see what your filter searches for. Is it somehow possible to keep the text in the textbox?










  2. Fenris
    Fenris avatar
    4 posts
    Member since:
    Feb 2015

    Posted 18 Feb 2015 in reply to Fenris Link to this post

    Got it working. After the Rebind() I had to retrieve the TextBox again and reset the text. et voila!
  3. UI for ASP.NET Ajax is Ready for VS 2017
Back to Top