Populate dropdowns with data from the database

Populating a dropdown list from database data can be very easily done in Stadium. We will use Field mapping to map data to texts and values of dropdown list.

Prerequisite:
SQLServer with Northwind database (to run sample below)
or create a table named Region with 2 fields: RegionDescription and RegionID in the database of your choice.

Steps

  1. Create a new application and drag a dropdown list on the Startpage designer
  2. Create a database connection
  3. Create a query and name it GetRegions
    SELECT RegionID,RegionDescription FROM dbo.Region;
  4. Open the StartPage.Load EventHandler
  5. Drag and drop the query GetRegions in the StartPage.Load designer
  6. Drag and Drop a SetValue action in the StartPage.Load designer
  7. Set the Target of SetValue to RadioButtonList.Options
  8. Follow the following steps to set the Value
  • Click on the dropdown button to select the source as NORTHWND_GetRegions.Results
    This will automatically show the fields that allow mapping.
  • For Text select MapItem and choose RegionDescription
  • For value select MapItem and choose RegionID

StadiumDesigner_fxMClb4hBK

The value code should appear as the value

= await ~.NORTHWND_GetRegions.Results.mapAsync(async MapItem => ({
	text: MapItem.RegionDescription,
	value: MapItem.RegionID
}))
  1. Click on preview
    image
    and you should be seeing your result! Congratulations!

Sample
PopulateRadioButtonListFromDatabase.sapz (7.2 KB)

1 Like