I have a radgrid with multiple custom filtering dropdowns.
I need to change the values in one of these dropdowns i.e. rebind to the datasource to get a subset of values based on the selection from the other dropdown.
Is this possible? Example code is below.
ASPX
<custom:DepartmentFilteringColumn DataField="Department_Name" HeaderText="Department" AllowFiltering="true"
UniqueName="Filter_Department" DataType="System.String" AutoPostBackOnFilter="True" CurrentFilterValue="%" >
<itemtemplate>
<telerik:RadComboBox ID="radcomboDepartment" Runat="server" Skin="Telerik"
DataSourceID="dsDepartments" AutoPostBack="true" ShowToggleImage="True"
OnSelectedIndexChanged="radcomboDepartment_SelectedIndexChanged" DataValueField="ID"
DataTextField="Name" DataMember="DefaultView" MarkFirstMatch="True" Width="300px" EnableScreenBoundaryDetection="true">
<ExpandAnimation Type="OutQuart" />
</telerik:RadComboBox>
</ItemTemplate>
<HeaderStyle Width="100px"></HeaderStyle>
</custom:DepartmentFilteringColumn>
<custom:EmployeeFilteringColumn DataField="Responsible_Employee_Name_String" HeaderText="Employee Name" AllowFiltering="true"
UniqueName="Filter_Employee" DataType="System.String" AutoPostBackOnFilter="True" CurrentFilterValue="Unallocated" >
<itemtemplate>
<telerik:RadComboBox ID="radcomboEmployee" Runat="server" Skin="Telerik"
ShowToggleImage="True" MarkFirstMatch="True" Width="300px" EnableScreenBoundaryDetection="true">
<ExpandAnimation Type="OutQuart" />
</telerik:RadComboBox>
</ItemTemplate>
<HeaderStyle Width="100px"></HeaderStyle>
</custom:EmployeeFilteringColumn>
VB
Imports
Microsoft.VisualBasic
Imports Telerik.Web.UI
Namespace
Ims.DepartmentFilteringColumnNameSpace
Public Class DepartmentFilteringColumn
Inherits GridTemplateColumn
Protected Overrides Sub SetupFilterControls(ByVal cell As TableCell)
Dim myDropDownListDepartment As New DropDownList()
myDropDownListDepartment.ID =
"myDropDownListDepartment"
myDropDownListDepartment.Width = Unit.Percentage(100)
myDropDownListDepartment.AutoPostBack =
True
Dim myDataSource As New SqlDataSource
myDataSource.SelectCommand = "SELECT 0 AS ID, ' All' AS Name UNION SELECT ID, Name FROM Departments ORDER BY Name"
myDataSource.ConnectionString = System.Configuration.ConfigurationManager.ConnectionStrings("IMS_Development").ToString()
myDropDownListDepartment.DataSource = myDataSource
myDropDownListDepartment.DataTextField =
"Name"
myDropDownListDepartment.DataValueField = "ID"
myDropDownListDepartment.DataBind()
AddHandler myDropDownListDepartment.SelectedIndexChanged, AddressOf myDropDownListDepartment_SelectedIndexChanged
cell.Controls.Add(myDropDownListDepartment)
End Sub
Protected Overrides Function GetFilterDataField() As String
Return Me.DataField
End Function
Protected Overrides Sub SetCurrentFilterValueToControl(ByVal cell As TableCell)
If Not Me.CurrentFilterValue Is String.Empty Then
Dim myDropDownListDepartment As DropDownList = cell.Controls(0)
If Me.CurrentFilterValue <> "" Then
If Not IsNothing(myDropDownListDepartment.Items.FindByText(Me.CurrentFilterValue)) Then
myDropDownListDepartment.Items.FindByText(Me.CurrentFilterValue).Selected = True
End If
End If
End If
End Sub
Protected Overrides Function GetCurrentFilterValueFromControl(ByVal cell As TableCell) As String
Dim myDropDownListDepartment As DropDownList = cell.Controls(0)
Me.CurrentFilterValue = myDropDownListDepartment.SelectedItem.Text
If Not myDropDownListDepartment.Items(myDropDownListDepartment.SelectedIndex).Value = "0" Then
Me.CurrentFilterFunction = GridKnownFunction.Contains
Else
Me.CurrentFilterFunction = GridKnownFunction.NoFilter
End If
Return Me.CurrentFilterValue
End Function
Public Overrides Function SupportsFiltering() As Boolean
Return True
End Function
Public Sub myDropDownListDepartment_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs)
Dim GridFilteringItem As GridFilteringItem = sender.parent.parent
Dim dropdownlist As DropDownList = sender
GridFilteringItem.FireCommandEvent(
"Filter", New Pair(dropdownlist.Items(dropdownlist.SelectedIndex).Text, Me.DataField))
End Sub
End Class
End
Namespace