Filter Data
Filter Content of Field Filter Dropdown

Description
This customization shows how to filter the contents of the Dropdown list of field filters.
Variables
Table Control
Select the table control displaying the database table
Parent Table
Select the parent table from which the filter is populated
Field Filter Dropdown Control
Select a field filter Dropdown list control displayed in the page
Field Name
Select a database table column which is used to populate the filter
Description Field
Select a descriptive parent table field (e.g: FirstName)
Filter Field
Select a database table column which will be used to filter content of the filter
Applies to
TableControl class
Code
 
''' 
'''Override the Populate${Field Filter Dropdown Control} to filter its contents.
''' 
Protected Overrides Sub Populate${Field Filter Dropdown Control}(ByVal selectedValue As String, ByVal maxItems As Integer)

    'Set up the WHERE clause.
    Dim wc As WhereClause = New WhereClause
    wc.iAND(${${Parent Table}ClassName}.${Filter Field}, BaseClasses.Data.BaseFilter.ComparisonOperator.EqualsTo, "somevalue")
    
    ' OrderBy takes two parameters
    ' ExpandForeignKeyColumn and isCaseSensitive   
    ' ExpandForeignKeyColumn = true will sort the dropdown based on the display foreign key column
    ' and not the foreign key column. 
    ' isCaseSensitive = true will sort the dropdown based on case sensitivity.
    Dim orderBy As OrderBy = New OrderBy(False, True)
    orderBy.Add(${${Parent Table}ClassName}.${Field Name},BaseClasses.Data.OrderByItem.OrderDir.Asc)

    Me.${Field Filter Dropdown Control}.Items.Clear()
    Dim itemValue As ${${Parent Table}RecordClassName}
    For Each itemValue In ${${Parent Table}ClassName}.GetRecords(wc, orderBy, 0, maxItems)
      
       ' Create the item and add to the list.
        Dim cvalue As String = itemValue.${Field Name}.ToString()
        Dim fvalue As String = itemValue.Format(${${Parent Table}ClassName}.${Description Field})
        Dim item As ListItem = New ListItem(fvalue, cvalue)
        Me.${Field Filter Dropdown Control}.Items.Add(item)        
    Next

    ' Set the selected value.
    SetSelectedValue(Me.${Field Filter Dropdown Control}, selectedValue)

    ' Add the All item.    
    Me.${Field Filter Dropdown Control}.Items.Insert(0, New ListItem(Page.GetResourceValue("Txt:All", "${Application Name}"), "--ANY--"))    
End Sub
     


  Privacy Statement