Dropdown List - display value/actual id

M

mervyntracy

Hi There,

I have recently started coding in asp.net (just 2 and a half days
now). I am writing a simple test app that gets data from a data base
and displays the value perfectly in the drop down list. However, each
display value is simply that - a display value and is pretty useless
to me further down the line unless I use the value as part of a select
to get the the key of the record. This would be inefficent so what I
would like to find out is if there is a way to immediately bind the
key value to the display value on the dropdown list object. This way,
when the value is selected, the user will see the display value but
behind the scene, I immediately have access to the key associated to
the display value. I have looked a a few options but none that I can
see will really help me over come my problem easily and I am sure that
there must be a way to bind the display value and the key to the same
control.

I hope that I have explained myself correctly.

Thanks
Mervyn

Dim manufactureData As MANUFACTURER = New MANUFACTURER()
Dim selectString as String()
selectString = "SELECT MANUFACTURER WITH SUSPENDED #
""Y"""
selectString &= " AND WITH MANUFACTURER_NAME # """""
selectString &= " BY-DSND MANUFACTURER_NAME"
manufactureData.selectFromDatabase(selectString)
While (manufactureData.nextRecord)
If cmdManufacturer.Items.Count = 0 Then
cmdManufacturer.Items.Add("Please Select..")
End If

cmdManufacturer.Items.Add(manufactureData.MANUFACTURE_NAME)
End While
 
P

PlatinumBay

mercvntracy,

Yes, the DropDownList supports setting both the text and the value, as in
the following example:

<asp:DropDownList id="stateList2" runat="server">
<asp:ListItem Selected="True" Value="" Text=""/>
<asp:ListItem Value="Confusion" Text="Confusion"/>
<asp:ListItem Value="Denial" Text="Denial"/>
</asp:DropDownList>

To set this programatically, the Add method takes an overload allowing you
to pass in a ListItem object.

Public Sub New(ByVal [text] As String, ByVal value As String)

Try the following:

cmdManufacturer.Items.Add(New ListItem(manufactureData.MANUFACTURE_NAME,
<value>))

Hope this helps,


Steve
 
M

mervyntracy

Hi There,

I have recently started coding in asp.net (just 2 and a half days
now). I am writing a simple test app that gets data from a data base
and displays the value perfectly in the drop down list. However, each
display value is simply that - a display value and is pretty useless
to me further down the line unless I use the value as part of a select
to get the the key of the record. This would be inefficent so what I
would like to find out is if there is a way to immediately bind the
key value to the display value on the dropdown list object. This way,
when the value is selected, the user will see the display value but
behind the scene, I immediately have access to the key associated to
the display value. I have looked a a few options but none that I can
see will really help me over come my problem easily and I am sure that
there must be a way to bind the display value and the key to the same
control.

I hope that I have explained myself correctly.

Thanks
Mervyn

Dim manufactureData As MANUFACTURER = New MANUFACTURER()
Dim selectString as String()
selectString = "SELECT MANUFACTURER WITH SUSPENDED #
""Y"""
selectString &= " AND WITH MANUFACTURER_NAME # """""
selectString &= " BY-DSND MANUFACTURER_NAME"
manufactureData.selectFromDatabase(selectString)
While (manufactureData.nextRecord)
If cmdManufacturer.Items.Count = 0 Then
cmdManufacturer.Items.Add("Please Select..")
End If

cmdManufacturer.Items.Add(manufactureData.MANUFACTURE_NAME)
End While


Hi Stevan,

This worked perfectly. Thank you very much for your help. Much
appreciated.

Regards,
Mervyn
 

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

No members online now.

Forum statistics

Threads
473,768
Messages
2,569,574
Members
45,048
Latest member
verona

Latest Threads

Top