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

Changing Values in Custom Filtering Dropdowns

1 Answer 86 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Richard
Top achievements
Rank 1
Richard asked on 11 Nov 2010, 11:45 PM
Hi

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

1 Answer, 1 is accepted

Sort by
0
Pavlina
Telerik team
answered on 17 Nov 2010, 12:39 PM
Hi Richard,

The project in the code library below shows how to use related RadComboBoxes for Insert and Update operations in RadGrid. Please check it out and let me know if it helps:
http://www.telerik.com/community/code-library/aspnet-ajax/general/using-related-radcomboboxes-in-radgrid.aspx

Greetings,
Pavlina
the Telerik team
Browse the vast support resources we have to jumpstart your development with RadControls for ASP.NET AJAX. See how to integrate our AJAX controls seamlessly in SharePoint 2007/2010 visiting our common SharePoint portal.
Tags
Grid
Asked by
Richard
Top achievements
Rank 1
Answers by
Pavlina
Telerik team
Share this question
or