Filter Data
Filter Dropdown List Box Content

Description
This example filters the content of a dropdown list box whose data comes from a foreign-key accessed field
Variables
Dropdown List Box control
Select the dropdown list box control
Record Control Class
Select the record control where this customization will be inserted
Display Table
Select a database table whose record is being added or updated
Display Field
Select the field in display table corresponding to the dropdown field
Parent Table
Select a parent table whose data is used to populate the Dropdown field
Dropdown Field
Select the field in parent table corresponding to the dropdown field
Filtering Field
Select a parent table field to base the filtering upon
Description Field
Select a descriptive parent table field (e.g: FirstName)
Applies to
RecordControl class
Code
 
/// 
/// Override the Populate${Dropdown Field}DropDownList function to filter contents of Dropdown list.
///     
protected override void Populate${Dropdown List Box control}DropDownList(string selectedValue,int maxItems)
{
    // Set up the WHERE clause.
    WhereClause wc = new WhereClause();      
    wc.iAND(${${Parent Table}ClassName}.${Filtering Field}, BaseClasses.Data.BaseFilter.ComparisonOperator.EqualsTo, "somevalue");

    // You can add additional WhereClause here
    // 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.
    OrderBy oB = new OrderBy(false, true);
    oB.Add(${${Parent Table}ClassName}.${Dropdown Field}, BaseClasses.Data.OrderByItem.OrderDir.Asc);    
    
    this.${Dropdown List Box control}.Items.Clear();        
    foreach (${${Parent Table}RecordClassName} itemValue in ${${Parent Table}ClassName}.GetRecords(wc, oB, 0, maxItems))
    {
        // Create the item and add to the list.
        string cvalue = itemValue.${Dropdown Field}.ToString();            
        string fvalue = itemValue.Format(${${Parent Table}ClassName}.${Description Field});            
        ListItem item = new ListItem(fvalue, cvalue);
        this.${Dropdown List Box control}.Items.Add(item);                  
    }

    // Set up the selected item.
    if( selectedValue != null && selectedValue.Length > 0 && !MiscUtils.SetSelectedValue(this.${Dropdown List Box control}, selectedValue))   
      {
          string fvalue = ${${Display Table}ClassName}.${Display Field}.Format(selectedValue);
          ListItem item = new ListItem(fvalue, selectedValue);
          item.Selected = true;
          this.${Dropdown List Box control}.Items.Insert(0, item);
       }
    
    // Add the Please Select item.    
    this.${Dropdown List Box control}.Items.Insert(0, new ListItem(Page.GetResourceValue("Txt:PleaseSelect", "${Application Name}"), "--PLEASE_SELECT--"));    
}
  


  Privacy Statement