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
- Create a new application and drag a dropdown list on the Startpage designer
- Create a database connection
- Create a query and name it GetRegions
SELECT RegionID,RegionDescription FROM dbo.Region;
- Open the StartPage.Load EventHandler
- Drag and drop the query GetRegions in the StartPage.Load designer
- Drag and Drop a SetValue action in the StartPage.Load designer
- Set the Target of SetValue to RadioButtonList.Options
- 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
The value code should appear as the value
= await ~.NORTHWND_GetRegions.Results.mapAsync(async MapItem => ({
text: MapItem.RegionDescription,
value: MapItem.RegionID
}))
- Click on preview
and you should be seeing your result! Congratulations!
Sample
PopulateRadioButtonListFromDatabase.sapz (7.2 KB)