By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
428,684 Members | 1,439 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 428,684 IT Pros & Developers. It's quick & easy.

Dropdown List - display value/actual id

P: n/a
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.MANUFACT URE_NAME)
End While

Jun 5 '07 #1
Share this Question
Share on Google+
2 Replies


P: n/a
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

<me*********@gmail.comwrote in message
news:11**********************@j4g2000prf.googlegro ups.com...
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.MANUFACT URE_NAME)
End While

Jun 6 '07 #2

P: n/a
On Jun 6, 9:09 am, mervyntr...@gmail.com wrote:
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.MANUFACT URE_NAME)
End While

Hi Stevan,

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

Regards,
Mervyn

Jun 6 '07 #3

This discussion thread is closed

Replies have been disabled for this discussion.