RadComboBox in RadGrid Filter Template

3 posts, 0 answers
  1. Eric Klein
    Eric Klein avatar
    183 posts
    Member since:
    Aug 2009

    Posted 15 Sep 2010 Link to this post

    I have a grid that is being populated OnNeeddDataSource
    <telerik:RadGrid runat="server" ID="RadGrid1" AllowPaging="True" AllowSorting="True"
     PageSize="20" AllowFilteringByColumn="True" EnableViewState="False"  AutoGenerateColumns="False" Skin="Office2007" GridLines="None" OnItemCreated="RadGrid1_ItemCreated" OnPreRender="RadGrid1_PreRender"

    In this grid the client column has a Filter Template that is a RadComboBox

    <telerik:GridBoundColumn SortExpression="ClientName" DataField="ClientName" HeaderText="Client Name"                                               HeaderStyle-Width="300px">
               <telerik:RadComboBox ID="RadComboBoxClientName" DataTextField="ClientName" DataValueField="ClientName"                                                      AppendDataBoundItems="true" SelectedValue='<%# ((GridItem)Container).OwnerTableView.GetColumn("ClientName").CurrentFilterValue %>'    runat="server" OnClientSelectedIndexChanged="ClientNameIndexChanged" Skin="Office2007">
         <telerik:RadScriptBlock ID="RadScriptBlock1" runat="server">
            <script type="text/javascript">
                 function ClientNameIndexChanged(sender, args) {
                   var tableView = $find("<%# ((GridItem)Container).OwnerTableView.ClientID %>");
                   if (args.get_item().get_value() == "0") {             tableView.filter("ClientName", args.get_item().get_value(), "NoFilter");
        else {
               tableView.filter("ClientName", args.get_item().get_value(), "EqualTo");
     </script> </telerik:RadScriptBlock>

    This all works fine except when I try to sort on the grid when I have set a filter.  The data in the grid is correct but the DropDown gets changed to *** ALL ***.

    I have tried the following code to select the by value
    protected void RadGrid1_ItemCreated(object sender, Telerik.Web.UI.GridItemEventArgs e)
                   if (e.Item is GridFilteringItem)
                       GridFilteringItem filterItem = (GridFilteringItem)e.Item;
                       RadComboBox combo = (RadComboBox)filterItem["ClientName"].FindControl("RadComboBoxClientName");
                       if (Session["AdvisorClientID"] == null)
                           ClientDataContext db = new ClientDataContext();
                           var clients = (from c in db.Clients
                                          select new
                                         .OrderBy(c => c.ClientName);
                           combo.DataSource = clients;
                           RadComboBoxItem newItem = new RadComboBoxItem();
                           newItem.Text = "*** ALL ***";
                           newItem.Value = "0";
                           combo.Items.Insert(0, newItem);
                           int test = RadGrid1.MasterTableView.FilterExpression.IndexOf("ClientName = \"");
                           if (test > 0)
                               string clientName = RadGrid1.MasterTableView.FilterExpression.Replace("(ClientName = \"", "");
                               clientName = clientName.Replace("\")", "");
                               combo.SelectedValue = clientName;// combo.FindItemByValue(clientName);
                           combo.Visible = false;

    Is there a way to keep the selected value in the combobox when the grid gets reloaded on sort?
  2. Shinu
    Shinu avatar
    17764 posts
    Member since:
    Mar 2007

    Posted 18 Sep 2010 Link to this post

    Hello Eric,

    I hope resetting the SelectedValue in PreRender event is better approach. Check the following forum link which discussed similar scenario.
    How to persist DropDownList selected index and value on postback from RadGrid FilterTemplate

  3. Brad H
    Brad H avatar
    31 posts
    Member since:
    Aug 2009

    Posted 23 Jan 2011 Link to this post

    I have read all of the replies to this topic and none really seem worthwhile.  Pre_Render may work for some but it did not for me.  I tried ViewState and Session on both the RadComboBox inside my FilterTemplate and the RadGrid itself.  The SelectedIndex/Value never persisted.  I chose instead to simply embrace the lack of functionality in this case and use a blank entry as my top selection.  This way, every time the user makes a selection, the index is changed and your events are fired.  It seems this is the way the RadComboBox was intended because it always resets to the top value and when you click the top value, no postback is fired.  Anyway, here's my code in case anyone wants to try something similar.

    ASPX:  I used an "All" item in the RadComboBox DataSource and an Empty RadComboBoxItem.  I use the "All" to display all results in code behind.
    <telerik:RadGrid ID="rgCallTagHistory" runat="server" AutoGenerateColumns="false"
                AllowFilteringByColumn="true" AllowSorting="true" Skin="Office2007" AllowMultiRowSelection="false"
                Width="750px" ShowFooter="false" PageSize="10" AllowPaging="true" Height="400px">
                    <Scrolling UseStaticHeaders="true" AllowScroll="true" />
                <GroupingSettings CaseSensitive="false" />
                        <telerik:GridBoundColumn ItemStyle-Wrap="false" ItemStyle-Width="75px" HeaderStyle-Width="75px"
                            AllowFiltering="true" DataType="System.String" ItemStyle-HorizontalAlign="Center"
                            HeaderStyle-HorizontalAlign="Center" DataField="AccessType" HeaderText="Type of Access"
                                <telerik:RadComboBox ID="comboAccessType" runat="server" DataSourceID="XmlDataSource1"
                                    DataTextField="Text" DataValueField="Value" AutoPostBack="true" OnSelectedIndexChanged="comboAccessType_SelectedIndexChanged"
                                    Width="75px" AppendDataBoundItems="true">
                                        <telerik:RadComboBoxItem Text="" Value="" />
          <asp:XmlDataSource ID="XmlDataSource1" runat="server">
                        <Item Value="All" Text="All"></Item>
                        <Item Value="Archive" Text="Archive"></Item>
                        <Item Value="Edit" Text="Edit"></Item>
                        <Item Value="Play" Text="Play"></Item>

    Public Sub comboAccessType_SelectedIndexChanged(ByVal sender As Object, ByVal e As RadComboBoxSelectedIndexChangedEventArgs)
            Dim filterExpression As String
            If e.Value = "All" Then
                filterExpression = ""
                filterExpression = "([AccessType] LIKE '" + e.Value + "')"
            End If
            rgCallTagHistory.MasterTableView.FilterExpression = filterExpression
        End Sub
Back to Top