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

RadTextBox text after rebind

1 Answer 64 Views
Input
This is a migrated thread and some comments may be shown as answers.
Fenris
Top achievements
Rank 1
Fenris asked on 18 Feb 2015, 03:23 PM
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?










1 Answer, 1 is accepted

Sort by
0
Fenris
Top achievements
Rank 1
answered on 18 Feb 2015, 04:31 PM
Got it working. After the Rebind() I had to retrieve the TextBox again and reset the text. et voila!
Tags
Input
Asked by
Fenris
Top achievements
Rank 1
Answers by
Fenris
Top achievements
Rank 1
Share this question
or