CodeCharge Studio All ASP PHP Perl ColdFusion Java C#.NET VB.NET

Dynamically Modify the WHERE and ORDER BY Clauses of a ListBox

When the List Source Type property of a list box is set to Table/View, the values that are used to populate the Listbox come from a database table or view. In this case, it is possible to use event code to specify the Where clause as well as the Order By clause which will be used in the SQL statement that retrieves records to be shown in the Listbox.

In our example, we have a Status List Box that is located in a Tasks Record form.

  1. In the Properties Window for the Listbox, set the Source Type property to Table/View.
  2. Add the Before Build Select event to the Listbox.
  3. Within the event, add the code below:


Function Tasks_Status_DataSource_BeforeBuildSelect(Sender)
  Tasks.Status.DataSource.Where = " status_id >2" 
  Tasks.Status.DataSource.Order = " status_id DESC"

End Function


function Tasks_Status_DataSource_BeforeBuildSelect(& $sender) {
global $Tasks;

  $Tasks->Status->DataSource->Where = " status_id >2"; 
  $Tasks->Status->DataSource->Order = " status_id DESC";



sub Tasks_Status_DataSource_BeforeBuildSelect() {

  $Tasks->{Status}->{DataSource}->{Where} = " status_id >2"; 
  $Tasks->{Status}->{DataSource}->{Order} = " status_id DESC";



<!---Tasks_status_BeforeBuildSelect --->

  <CFSET strWhereStatus=" status_id > 2"> 
  <CFSET strOrderStatus=" status_id DESC"> 



  e.getCommand().setWhere(" status_id > 2"); 
  e.getCommand().setOrder(" status_id DESC");



CType(statusDataCommand,TableCommand).Where="age_id > 5"



((TableCommand)statusDataCommand).Where="age_id > 5";

See Also:

Before Build Select event

On-line, printable versions and updates