set the selected value for drop down from a database query (VB.NET)
-
I manually set my drop down items (ex. MyDropDown.Items.Add("something")) since our database is not yet complete data and to avoid typographical errors. Basically i just want to know how can i set the selected value of my DropDownList based from my database query. to explain further my problem ill give a scenario: my dropdown items defined as "a", "b", "c". then the result of my query is "c" ... how can i set "c" as my 'SelectedValue'? thanks in advance! :)
-
I manually set my drop down items (ex. MyDropDown.Items.Add("something")) since our database is not yet complete data and to avoid typographical errors. Basically i just want to know how can i set the selected value of my DropDownList based from my database query. to explain further my problem ill give a scenario: my dropdown items defined as "a", "b", "c". then the result of my query is "c" ... how can i set "c" as my 'SelectedValue'? thanks in advance! :)
hi Look at this Article , but instead use a Combobox http://www.codeproject.com/KB/vb/N-Tier_Application_VB.aspx[^] its Simple
Vuyiswa Maseko, Sorrow is Better than Laughter, it may Sadden your Face, but It sharpens your Understanding VB.NET/SQL7/2000/2005 http://vuyiswamb.007ihost.com http://Ecadre.007ihost.com vuyiswam@tshwane.gov.za
-
I manually set my drop down items (ex. MyDropDown.Items.Add("something")) since our database is not yet complete data and to avoid typographical errors. Basically i just want to know how can i set the selected value of my DropDownList based from my database query. to explain further my problem ill give a scenario: my dropdown items defined as "a", "b", "c". then the result of my query is "c" ... how can i set "c" as my 'SelectedValue'? thanks in advance! :)
You can select the needed value from the database.If DropDownList1 be the dropdownlist which contain the values a,b,c,d.You can make the selected item of the dropdownlist as that value.If you used a DataReader to retrive the data from database DropDownList1.SelectedItem =dr(0).ToString() where dr is my DataReader Hope This Code Help You
-
I manually set my drop down items (ex. MyDropDown.Items.Add("something")) since our database is not yet complete data and to avoid typographical errors. Basically i just want to know how can i set the selected value of my DropDownList based from my database query. to explain further my problem ill give a scenario: my dropdown items defined as "a", "b", "c". then the result of my query is "c" ... how can i set "c" as my 'SelectedValue'? thanks in advance! :)
If the DropDown's style is set to something other than
DropDownList
then you can just doDropDown.SelectedText = "c"
. (Setting DropDown.SelectedText when the DropDownStyle is set toDropDownList
won't have any effect.) Or, perhaps you might want to save the SelectedIndex instead of the Text? That way you can just set the SelectedIndex when you retrieve the value from the database.