///
/// 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--"));
}
|