Last post Oct 24, 2011 09:50 AM by mattsgrandad
Oct 20, 2011 10:26 PM|mattsgrandad|LINK
Does anyone have an example of coding for a dropdown list on a form on a cshtml page.
Two things specifically:
1. Dropdown list to be prepopulated from a database table (an sdf file)
2. How do I then access the selecetd value from the form
Any help gratefully received.
Oct 21, 2011 04:03 AM|BlogDog|LINK
You need to databind the dropdown list with a data source. Here's one tutorial: http://www.progtalk.com/viewarticle.aspx?articleid=194
To retrieve the selected value: Specify an event handler like a submit button or even the ddl itself once selction is made. Then retrieve in your code behind something like:
dim selectedValue as string
selectedValue = ddl1.SelectedValue.ToString
Oct 24, 2011 09:50 AM|mattsgrandad|LINK
Although it didn't provide the answer, it set me on the right path so thanks for that.
Because my page is cshtml I was looking for cshtml compatible code.
The eventual solution I came up is as follows (dropdown populated with a list of 'FieldA' from 'TableA'):
// Retrieve records for the list
db = Database.Open("StarterSite");
selectrecords = "SELECT
* FROM TableA ";
selected = "";
selected = Request.Form["dropdown"];
Selected value is