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

[Solved] Interdependent Filter Dropdowns

5 Answers 143 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Marc Lee
Top achievements
Rank 2
Marc Lee asked on 22 Jan 2010, 01:36 AM
I have a RadGrid with State, County and Customer columns.  Each column has a dropdown for filtering.  I need the County filter to be hidden and empty until a state is selected from the State filter.  Once a user has selected a state in the State filter dropdown, the County filter should become visible and contain ONLY counties that correspond to the chosen state.  I can't seem to get the County dropdown to be affected in any way.

Anyone have any ideas?

Here's some code:

    <telerik:RadGrid ID="RadGrid1" runat="server" AllowFilteringByColumn="True" AllowPaging="True" 
      AllowSorting="True" AutoGenerateColumns="False" DataSourceID="odsVendorFees" GridLines="None" 
      EnableAjaxSkinRendering="true"
      <MasterTableView DataSourceID="odsVendorFees"
        <RowIndicatorColumn> 
          <HeaderStyle Width="20px"></HeaderStyle> 
        </RowIndicatorColumn> 
        <ExpandCollapseColumn> 
          <HeaderStyle Width="20px"></HeaderStyle> 
        </ExpandCollapseColumn> 
        <Columns> 
          <telerik:GridBoundColumn DataField="StateName" HeaderText="StateName" SortExpression="State" 
            UniqueName="STATENAME"
            <FilterTemplate> 
              <asp:TextBox runat="server" ID="TextBox1" Style="display: none;" /> 
              <telerik:RadComboBox runat="server" ID="ddFilterSN" AutoPostBack="true" DataSourceID="odsStates" 
                DataTextField="StateName" DataValueField="StateCode" OnSelectedIndexChanged="ddFilterSN_SelectedIndexChanged" 
                Skin="Outlook" AppendDataBoundItems="true"
                <Items> 
                  <telerik:RadComboBoxItem runat="server" id="iPubNameBlank" Text="" Value="" /> 
                  <telerik:RadComboBoxItem runat="server" id="iPubNameClear" ForeColor="Blue" Font-Italic="true" 
                    Text="Show All States" Value="Clear Search" /> 
                </Items> 
              </telerik:RadComboBox> 
            </FilterTemplate> 
          </telerik:GridBoundColumn> 
          <telerik:GridBoundColumn DataField="CountyName" HeaderText="CountyName" SortExpression="County" 
            UniqueName="COUNTYNAME"
            <FilterTemplate> 
              <asp:TextBox runat="server" ID="TextBox2" Style="display: none;" /> 
              <telerik:RadComboBox runat="server" ID="ddFilterCN" AutoPostBack="true" DataTextField="CountyName" 
                DataValueField="CountyName" OnSelectedIndexChanged="ddFilterCN_SelectedIndexChanged" 
                Skin="Outlook" AppendDataBoundItems="true"
                <Items> 
                  <telerik:RadComboBoxItem runat="server" id="iPubNameBlank" Text="" Value="" /> 
                  <telerik:RadComboBoxItem runat="server" id="iPubNameClear" ForeColor="Blue" Font-Italic="true" 
                    Text="Show All Counties" Value="Clear Search" /> 
                </Items> 
              </telerik:RadComboBox> 
            </FilterTemplate> 
          </telerik:GridBoundColumn> 
          <telerik:GridBoundColumn DataField="CustomerName" HeaderText="CustomerName" SortExpression="Customer Name" 
            UniqueName="CustomerName"
          </telerik:GridBoundColumn> 
        </Columns> 
      </MasterTableView> 
    </telerik:RadGrid> 
 


    Public Sub ddFilterSN_SelectedIndexChanged(ByVal sender As ObjectByVal e As RadComboBoxSelectedIndexChangedEventArgs) 
        ' filter the grid based on state name 
        Dim filterItem As GridFilteringItem = DirectCast(RadGrid1.MasterTableView.GetItems(GridItemType.FilteringItem)(0),  _ 
        GridFilteringItem) 
        Dim ddCN As RadComboBox = CType(filterItem("COUNTYNAME").Controls(3), RadComboBox) 
 
        If e.Value = "Clear Search" Then 
            ddCN.Visible = False 
            RadGrid1.MasterTableView.FilterExpression = Nothing 
            RadGrid1.Rebind() 
        Else 
            Dim lstCounties As List(Of County) = CountyDAL.GetCountiesByStateCode(e.Value) 
 
            TryCast(filterItem("STATENAME").Controls(1), TextBox).Text = e.Text 
            filterItem.FireCommandEvent("Filter"New Pair("EqualTo""STATENAME")) 
 
            ddCN.DataSource = lstCounties 
            ddCN.DataBind() 
            ddCN.Visible = False 
            RadGrid1.DataBind() 
        End If 
    End Sub 
 




5 Answers, 1 is accepted

Sort by
0
Princy
Top achievements
Rank 2
answered on 22 Jan 2010, 12:38 PM
Hello Marc,

Check out the following online demo which illustrtates on how combobox instances can interact with each other. You can implement the same in grid. You can use the onClientLoad event of the comboboxes to access the comboboxes instead of the pageLoad client event.
js:
 var countriesCombo;
function ClientLoad(sender, args) 
   {            
       countriesCombo = sender; 
   } 

Hope this helps..
Princy.
0
Dimo
Telerik team
answered on 22 Jan 2010, 12:52 PM
....and this is the demo Princy is talking about :)

http://demos.telerik.com/aspnet-ajax/combobox/examples/functionality/multiplecomboboxes/defaultcs.aspx


Best wishes,
Dimo
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
0
Marc Lee
Top achievements
Rank 2
answered on 22 Jan 2010, 08:18 PM
Thanks for your efforts, but I'm not having a problem with the comboboxes specifically.  I know how to make them interact with each other under normal circumstances.  In this case, however, I can't even get the 2nd RadComboBox to respond to any event - specifically with rebinding to a datasource.  If I put a code break within a specific event *after* the rebinding has occurred, I can see that the 2nd RadComboBox has the data, but it does not show up in real time.  It's almost as if the grid needs to be refreshed, but I've tried rebinding the grid and even rebinding the MasterTableView, but nothing works.

I'm sure I'm missing something simple, but I just can't see what it is.


Thanks!

Marc
0
Accepted
Dimo
Telerik team
answered on 28 Jan 2010, 09:12 AM
Hi Marc Lee,

Here is one more demo that you can review:

http://demos.telerik.com/aspnet-ajax/grid/examples/programming/filtertemplate/defaultcs.aspx

You can control the RadComboBoxes' visibility in RadGrid_PreRender by using

GridItem[] items = RadGrid1.MasterTableView.GetItems(GridItemType.FilteringItem);
(items[0] as GridFilteringItem).FindControl("RadComboBoxCity").Visible = true;

Regards,
Dimo
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
0
Marc Lee
Top achievements
Rank 2
answered on 02 Feb 2010, 08:37 PM
Dimo,

Thanks!  Between your suggested demo and the Google-style filtering demo, I was able to get this working.  Thanks for coming back and posting another possible solution!


Marc
Tags
Grid
Asked by
Marc Lee
Top achievements
Rank 2
Answers by
Princy
Top achievements
Rank 2
Dimo
Telerik team
Marc Lee
Top achievements
Rank 2
Share this question
or