Populating the Combo Boxes  

In this step we set the properties and bind the data for the two DBCombo controls.

We add a new ControlBinder for each DBCombo and set the control's default selection to the information stored in the Products’ records.

Finally, we add the code that preloads the DBCombo controls with data when the application form initially opens.

To populate the Combo boxes:

  1. Set the properties for the DBCombo controls from the Properties dialog box. In this tutorial, the properties are set as:

 

DBCombo

Table Property

FieldName Property

DBCombo1

tblCategories

CAT_NAME

DBCombo2

tblProviders

NAME

 

NOTE–

You can filter the data displayed in the Combo boxes by entering selection criteria in the Criteria property. Selection criteria is entered in standard TCL SELECT statement form (excluding the word SELECT and the file name) using your database server syntax.

For example, the TCL SELECT statement SELECT CATEGORIES WITH @ID = “1]” BY NAME is entered as WITH @ID = “1]” BY NAME.

  1. Select the DBDataBinder control and then click the ... button from the ControlBindings property of the Properties dialog box.

The ControlBinder Collection Editor dialog box displays.

  1. Click the Add button to add as many ControlBinders as necessary. In this tutorial, two ControlBinders are added to the six existing ControlBinders.

  2. Set the properties for each of the new ControlBinders. In this tutorial, the properties are set as:

 

ControlBinder

Control Property

FieldName Property

ControlBinder7

DBCombo1

CATEGORY

ControlBinder8

DBCombo2

PROVIDER

 

NOTE–

The Products records store the item-ID of the Categories and Providers. This enables the DBCombo boxes to synchronize the selected item with the item-ID on file (even though the name and description of the Categories and Providers are displayed, the item-ID is not).

  1. Click OK.

  2. Insert the code to preload the DBCombo boxes with data when the application form initially opens.

When the ASP.NET application starts, the database server connection opens, but we do not access any data. To preload the DBCombo boxes with data when the page opens, we need to execute the data selection and retrieval on the server site. This is accomplished by initiating calls to the server.

To accomplish this we add the following line of code in the openTables() method:

Dim i As Integer = Me.DBCombo1.Items.Count

This code selects the file from the Categories file and returns the data to the Web page. Consequently, running this count also runs the selection on the Providers file, thus eliminating the need to run a separate count on the Providers file.

  1. Run and test the application.

Note that the Combo boxes display data when the page loads. When selecting a Category or a Provider, saving the Products record saves the item-ID (not the text in the Combo boxes). This is performed automatically by the PickDP libraries.