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

grid filtering related comboxes

1 Answer 78 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Khanh
Top achievements
Rank 1
Khanh asked on 09 Jun 2010, 09:07 PM
Hi,
I have filtering turned on and using template for radcomboboxes.  I would like the filtering comboboxes to be related to each other.  I have a combox called dept and I filter it the other combox called employee should contain a list of employees belonging to the selected dept.

On page load, dept is correct with the selectedvalue being the user's home dept.  Employee is also correct because it only list the employees for that dept.  When I select a different dept, my employee combobox is now empty even though I see it hitting RadComboBoxSelectedIndexChangedEventArg

I would appreciate any help you can give.

Khanh

<FilterTemplate> 
  <telerik:RadComboBox ID="DeptID" runat="server" MarkFirstMatch="True" DataSourceID="SqlDept" 
      DataTextField="DeptName" DataValueField="DeptID" Width="200" AllowCustomText="false" 
      OnClientDropDownClosing="OnClientDropDownClosing" EnableItemCaching="false" EnableLoadOnDemand="false" 
      EnableVirtualScrolling="false" ShowMoreResultsBox="False"  
      AutoPostBack="false" OnSelectedIndexChanged="DeptLoadEmployee" 
      TabIndex="1" ToolTip="DeptID" AppendDataBoundItems="true" 
      OnClientSelectedIndexChanged="SelectedIndexChangedDeptID" 
      SelectedValue='<%# TryCast(Container, GridItem).OwnerTableView.GetColumn("DeptID").CurrentFilterValue %>'
      <Items> 
         <telerik:RadComboBoxItem Text="All" Value="" /> 
      </Items> 
  </telerik:RadComboBox> 
  <telerik:RadScriptBlock ID="RadScriptBlock3" runat="server"
    <script type="text/javascript"
      function SelectedIndexChangedDeptID(sender, args) { 
        var tableView = $find("<%# TryCast(Container, GridItem).OwnerTableView.ClientID %>"); 
        tableView.filter("DeptID", args.get_item().get_value(), "EqualTo"); 
      } 
    </script> 
  </telerik:RadScriptBlock> 
</FilterTemplate>
<FilterTemplate> 
  <telerik:RadComboBox ID="EmployeeID" runat="server" MarkFirstMatch="True" DataTextField="EmployeeName" 
    DataValueField="EmployeeID" Width="70" Height="203" AllowCustomText="false" 
    OnClientDropDownClosing="OnClientDropDownClosing" EnableItemCaching="false" EnableLoadOnDemand="false" 
    EnableVirtualScrolling="false" OnClientSelectedIndexChanged="SelectedIndexChangedEmployeeID" 
    ShowMoreResultsBox="False" AutoPostBack="false" ToolTip="EmployeeID" AppendDataBoundItems="true" 
    SelectedValue='<%# TryCast(Container, GridItem).OwnerTableView.GetColumn("EmployeeID").CurrentFilterValue %>'
  </telerik:RadComboBox> 
  <telerik:RadScriptBlock ID="RadScriptBlock4" runat="server"
    <script type="text/javascript"
      function SelectedIndexChangedEmployeeID(sender, args) { 
        var tableView = $find("<%# TryCast(Container, GridItem).OwnerTableView.ClientID %>"); 
        tableView.filter("EmployeeID", args.get_item().get_value(), "EqualTo"); 
      } 
    </script> 
  </telerik:RadScriptBlock> 
</FilterTemplate> 


code behind
Protected Sub DeptLoadEmployee(ByVal source As Object, ByVal e As Telerik.Web.UI.RadComboBoxSelectedIndexChangedEventArgs) 
        Dim editedItem As GridFilteringItem = TryCast(TryCast(source, RadComboBox).NamingContainer, GridFilteringItem) 
 
        Dim DeptID As RadComboBox = TryCast(source, RadComboBox) 
        Dim EmployeeID As RadComboBox = TryCast(editedItem.FindControl("EmployeeID"), RadComboBox) 
        EmployeeID.Items.Clear() 
 
        EmployeeID.DataSource = LoadEmployeeID(e.Value) 
        EmployeeID.DataBind() 
        AddBlankItemtoCombo(EmployeeID) 
        EmployeeID.SelectedIndex = 0        
    End Sub 
Protected Function LoadEmployeeID(ByVal ID As String) As DataTable 
  Dim dt As New DataTable() 
  If Not ID = String.Empty Then 
    Dim connection As New SqlConnection(ConfigurationManager.ConnectionStrings("TEST").ConnectionString)             
    Dim cmd As New SqlCommand 
    cmd.CommandType = CommandType.StoredProcedure 
    cmd.CommandText = "P_S_EmployeeByDept" 
    cmd.Connection = connection 
    Dim adapter As New SqlDataAdapter() 
    adapter.SelectCommand = cmd 
    adapter.SelectCommand.Parameters.AddWithValue("@DeptID", ID) 
    adapter.Fill(dt) 
  End If 
  Return dt 
End Function 
Protected Sub AddBlankItemtoCombo(ByVal i As Object) 
  Dim blankItem As New RadComboBoxItem() 
  blankItem.Height = CType(10, Unit) 
  i.Items.Insert(0, blankItem) 
End Sub 

Protected Sub RadGrid1_ItemDataBound(ByVal sender As Object, ByVal e As Telerik.Web.UI.GridItemEventArgs) Handles RadGrid1.ItemDataBound 
  If TypeOf e.Item Is GridFilteringItem Then 
    Dim filter As GridFilteringItem = DirectCast(e.Item, GridFilteringItem) 
    Dim DeptID As RadComboBox = DirectCast(filter.FindControl("DeptID"), RadComboBox) 
    Dim EmployeeID As RadComboBox = DirectCast(filter.FindControl("EmployeeID"), RadComboBox) 
    If Not IsPostBack Then 
      If Session("DeptID") IsNot Nothing Then 
        DeptID.SelectedValue = Session("DeptID") 
        EmployeeID.DataSource = LoadUnitID(DeptID.SelectedValue) 
        EmployeeID.DataBind() 
        AddBlankItemtoCombo(EmployeeID) 
      End If 
      Dim columnID As GridColumn = RadGrid1.MasterTableView.GetColumnSafe("DeptID") 
      columnID.CurrentFilterValue = DeptID.SelectedValue 
    End If 
  End If         
End Sub 

1 Answer, 1 is accepted

Sort by
0
Pavlina
Telerik team
answered on 10 Jun 2010, 12:27 PM
Hello Khanh,

Check out the following online demo which illustrates on how combobox instances can interact with each other. You can implement the same in grid.
http://demos.telerik.com/aspnet-ajax/combobox/examples/functionality/multiplecomboboxes/defaultcs.aspx

Kind regards,
Pavlina
the Telerik team

Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
Tags
Grid
Asked by
Khanh
Top achievements
Rank 1
Answers by
Pavlina
Telerik team
Share this question
or