473,387 Members | 1,504 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,387 software developers and data experts.

Dropdownlist anyone ???

Hi everyone

I'm developing an wep application, I got stuck into a problem.
My database has a table which has 2 fields
Table1

X Y
A Apple
B Banana
C Cat
D Dog

I would like to ask if there is a way so that I can add these two columns
into my dropdown list which will look like this

Apple
Banna
Cat
Dog

whichever values I select from the dropdownlist I wold like to get the
equivalent value; for instance
if I choose Cat, I want to get the value C for later use.

Thanks for any help


Nov 18 '05 #1
2 1067
You just need to tell the DataTextField and DataValueField properties the
name or index of the column from the dataset. The dropdownlist will display
one and return the other. Here's some code:
Private Sub Page_Load _
(ByVal sender As System.Object, _
ByVal e As System.EventArgs) _
Handles MyBase.Load
If Not IsPostBack Then
Dim ds As New DataSet
ds = CreateDataset()
DropDownList1.DataSource = ds.Tables(0)
DropDownList1.DataTextField = "Item_name"
DropDownList1.DataValueField = "Item_value"
DropDownList1.DataBind()
End If
End Sub
Private Sub Button1_Click _
(ByVal sender As Object, _
ByVal e As System.EventArgs) _
Handles Button1.Click
Label1.Text = DropDownList1.SelectedValue
End Sub
Function CreateDataset() As DataSet
Dim ds As New DataSet
Dim dt As New DataTable
Dim dr As DataRow
dt.Columns.Add(New DataColumn _
("Item_value", GetType(String)))
dt.Columns.Add(New DataColumn _
("Item_name", GetType(String)))
dr = dt.NewRow
dr(0) = "Y"
dr(1) = "X"
dt.Rows.Add(dr)
dr = dt.NewRow
dr(0) = "A"
dr(1) = "Apple"
dt.Rows.Add(dr)
dr = dt.NewRow
dr(0) = "B"
dr(1) = "Banana"
dt.Rows.Add(dr)
dr = dt.NewRow
dr(0) = "C"
dr(1) = "Cat"
dt.Rows.Add(dr)
dr = dt.NewRow
dr(0) = "D"
dr(1) = "Dog"
dt.Rows.Add(dr)
ds.Tables.Add(dt)
Return ds
End Function
"Hai Nguyen" <ha******@neo.tamu.edu> wrote in message
news:ej**************@TK2MSFTNGP09.phx.gbl...
Hi everyone

I'm developing an wep application, I got stuck into a problem.
My database has a table which has 2 fields
Table1

X Y
A Apple
B Banana
C Cat
D Dog

I would like to ask if there is a way so that I can add these two columns
into my dropdown list which will look like this

Apple
Banna
Cat
Dog

whichever values I select from the dropdownlist I wold like to get the
equivalent value; for instance
if I choose Cat, I want to get the value C for later use.

Thanks for any help


Nov 18 '05 #2
Thanks it works

"Hai Nguyen" <ha******@neo.tamu.edu> wrote in message
news:ej**************@TK2MSFTNGP09.phx.gbl...
Hi everyone

I'm developing an wep application, I got stuck into a problem.
My database has a table which has 2 fields
Table1

X Y
A Apple
B Banana
C Cat
D Dog

I would like to ask if there is a way so that I can add these two columns
into my dropdown list which will look like this

Apple
Banna
Cat
Dog

whichever values I select from the dropdownlist I wold like to get the
equivalent value; for instance
if I choose Cat, I want to get the value C for later use.

Thanks for any help

Nov 18 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: kamaumalone | last post by:
I have a dropdownlist which lives inside of a repeater. The repeater accepts user input via textboxes and the aforementioned dropdownlist. The repeater accepts phone numbers and allows for an...
0
by: Kimberly Walker | last post by:
Im farily new to the .Net so please bear with me. I have several dropdownlist that is bound to a sql string. For example dim sqlstring as string="Select books from SuborgT where books=New" I...
1
by: Aaron Prohaska | last post by:
I'm having the problem with this drop down list on postback. For some reason both the ListItems get selected when I change the selected item. Using the code below I'm building the drop down list in...
10
by: dhnriverside | last post by:
Hi guys Still having a problem with this dropdownlist. Basically, I've got 4. The first 2 work fine, then my code crashes on the 3rd. ddlEndTimeHour.Items.FindByValue(endTime).Selected =...
8
by: utterberg | last post by:
Hi I'm adding two dropdownlist in my webform by clicking a button. I fill the first dropdown with some values from my DB and the other one when I choose from the first dropdown. But since theese...
4
by: David | last post by:
Hi all, I am doing this in a web page... I have a dropdownlist that autopostback. This sets me a filter criteria for items to display in a datalist. In the datalist, I have edit...
1
by: glenn | last post by:
Hi folks, I need to have two ddl's in one DataGrid cell. The first ddl has a list of company names and the second has a list of contact names that work in the company name that was selected in...
15
by: glenn | last post by:
Hi folks, I have a DropDownList in a DataGrid that is populated from records in a database. I want to add a value that might be a string such as "Select a Company" for the first item since an...
3
by: Iain | last post by:
Hi All I have 2 DropDownList boxes on a page. The first (id= "Operation") is populated on PageLoad with the contents of a database table. The second id="WorkStations" will not be populated...
5
by: revbart | last post by:
Yep, that's me. I'll bet I've read a hundred articles somewhere or another, but I just can't get the thing to work. I'm working on a custom solution. One of the major UIs includes a calendar-style...
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
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
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
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

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.