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
code behind
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>
|
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 |