binding data to drop down menu

E

Eric Layman

HI,

I have a select menu

<select id="country" runat="server" class="myformat ">

<option value="AFGHANISTAN">AFGHANISTAN</option>

<option value="ALBANIA">ALBANIA</option>

<option value="ALGERIA">ALGERIA</option>



The option value data are all keyed in manually



Right now im doing a edit form.



when the data is retrieve form the db, it will auto bind the value to the
country drop down list.

are there any simple ways to do that?



Pls advise.



Thanks
 
L

Lisa Ashley Rafter

HI,

I have a select menu

<select id="country" runat="server" class="myformat ">

<option value="AFGHANISTAN">AFGHANISTAN</option>

<option value="ALBANIA">ALBANIA</option>

<option value="ALGERIA">ALGERIA</option>

The option value data are all keyed in manually

Right now im doing a edit form.

when the data is retrieve form the db, it will auto bind the value to the
country drop down list.

are there any simple ways to do that?

Pls advise.

Thanks


----------------------------------------------------------

----------------------------------------------------------
color]

Hi Eric,
Try this....
Private Sub loadAndSetDropdown(ByRef pDdl As DropDownList, ByRef
pdt As DataTable, ByVal psSetVal As String)
pDdl.Items.Clear()
Dim dr As DataRow
Dim lbItem As ListItem
For Each dr In pdt.Rows
lbItem = New ListItem
lbItem.Value = dr("code")
lbItem.Text = dr("descr")
pDdl.Items.Add(lbItem)
If CStr(lbItem.Value) = psSetVal Then
pDdl.SelectedValue = psSetVal
End If
Next
End Sub
Pass in the dropdown list (in my example, it'd be myDropdown like I
declare it below), the datatable you get back form your webservice/
database connection, and a "set value". This code works w/ an asp
dropdown list (not a plain old HTML dropdown like you have above).
Here's the HTML to declare it
<asp:dropdownlist id=myDropdown runat="server"></asp:dropdownlist>
Hope that helps,
Lisa Ashley Rafter
 
E

Eric Layman

Lisa Ashley Rafter said:
HI,

I have a select menu

<select id="country" runat="server" class="myformat ">

<option value="AFGHANISTAN">AFGHANISTAN</option>

<option value="ALBANIA">ALBANIA</option>

<option value="ALGERIA">ALGERIA</option>

The option value data are all keyed in manually

Right now im doing a edit form.

when the data is retrieve form the db, it will auto bind the value to the
country drop down list.

are there any simple ways to do that?

Pls advise.

Thanks


----------------------------------------------------------

----------------------------------------------------------
color]

Hi Eric,
Try this....
Private Sub loadAndSetDropdown(ByRef pDdl As DropDownList, ByRef
pdt As DataTable, ByVal psSetVal As String)
pDdl.Items.Clear()
Dim dr As DataRow
Dim lbItem As ListItem
For Each dr In pdt.Rows
lbItem = New ListItem
lbItem.Value = dr("code")
lbItem.Text = dr("descr")
pDdl.Items.Add(lbItem)
If CStr(lbItem.Value) = psSetVal Then
pDdl.SelectedValue = psSetVal
End If
Next
End Sub
Pass in the dropdown list (in my example, it'd be myDropdown like I
declare it below), the datatable you get back form your webservice/
database connection, and a "set value". This code works w/ an asp
dropdown list (not a plain old HTML dropdown like you have above).
Here's the HTML to declare it
<asp:dropdownlist id=myDropdown runat="server"></asp:dropdownlist>
Hope that helps,
Lisa Ashley Rafter

Hi Lisa,

Thanks for replying.

But the option values r not drawn from db

by default, the country lits are hand typed.

then when use registers, they choose a country and save the country to a db

right now they they doing editing, it mus also pull out the country they
selected previously.

because the list is hand written; it would be a hideous task to indiviually
compare the db value against the list.....
 
L

Lisa Ashley Rafter

HiLisa,

Thanks for replying.

But the option values r not drawn from db

by default, the country lits are hand typed.

then when use registers, they choose a country and save the country to a db

right now they they doing editing, it mus also pull out the country they
selected previously.

because the list is hand written; it would be a hideous task to indiviually
compare the db value against the list.....


----------------------------------------------------------

----------------------------------------------------------
http://www.usenet.com- Hide quoted text -

- Show quoted text -

Eric ,
You want to find out what country they selected?
Lisa
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,065
Latest member
OrderGreenAcreCBD

Latest Threads

Top