473,395 Members | 1,652 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

Dropdown List - display value/actual id

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
2 2047
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: middletree | last post by:
For an ASp Intranet app, I have some code that should work, but I am not able to make it happen for some reason, after spending considerable time on this. I am pretty thick when it comes to...
6
by: San Smith | last post by:
I have a dropdown list box with list of item. When I read the data from database I want to display that value(one of the item in the drop down box) in the dropdown list box. How to do that in a...
3
by: Tim Mavers | last post by:
I am looking for a control (freeware or commercial) that operates like a standard ASP.NET dropdown list, but is able to display heirarchies in the actual dropdown list. This can be similar to a...
3
by: RJN | last post by:
Hi The texts in the dropdown are too long and the width is not sufficient to show the entire text. Increasing the width is not an option. Is there a way to show the selected item text as a...
5
by: jung_h_park | last post by:
From: jung_h_park@yahoo.com Newsgroups: microsoft.public.dotnet.framework.aspnet Subject: Dropdown List not retaining its SelectedValue Date: Mon, 26 Jun 2006 21:02:57 -0700 Hello, My...
0
by: Kay | last post by:
Hello, I have written my own custom control and I want one of its properties to display as a dropdown list when clicked, so the user can select from the list, it would be similar to the asp...
0
by: Kay O'Keeffe | last post by:
Hello, I have written my own custom control and I want one of its properties to display as a dropdown list when clicked, so the user can select from the list, it would be similar to the asp...
1
by: luispunchy | last post by:
I have an accordion style dropdown list/sublist menu (functions similar to the "today on WebMD video" widget found on http://www.webmd.com/) - it will allow users to click on a headline (from the...
4
by: zion4ever | last post by:
Hello good people, Please bear with me as this is my first post and I am relative new to ASP. I do have VB6 experience. I have a form which enables users within our company to do an intranet...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.