473,396 Members | 2,059 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,396 software developers and data experts.

Using the DataTextField and DataValue Field in a ListBox

Hi,

I am trying to take from a database 3 values, concatenate the first two
of them and insert them in a ListBox (in the DataTextField) and the 3rd
value in the DataValueField.

The problem is that I am able only to add the first two values
concatenated (using the DataReader) but the DataValueField is not
taking any new value, it is taking the value of the text.

Can you please help me to solve this problem?

Sep 20 '06 #1
4 4272
What do you think your car mechanic will answer you if you call him
complaying that the car has a problem?

Post your code.

--
Eliyahu Goldin,
Software Developer & Consultant
Microsoft MVP [ASP.NET]
"l7alabeh" <l7******@gmail.comwrote in message
news:11**********************@m73g2000cwd.googlegr oups.com...
Hi,

I am trying to take from a database 3 values, concatenate the first two
of them and insert them in a ListBox (in the DataTextField) and the 3rd
value in the DataValueField.

The problem is that I am able only to add the first two values
concatenated (using the DataReader) but the DataValueField is not
taking any new value, it is taking the value of the text.

Can you please help me to solve this problem?

Sep 20 '06 #2
This is the code:

Sub ListBoxBind()

connstrconf.ConnectionString = strcnnconf

Dim NameDataReader As OleDbDataReader
Dim NameOleDbCommand As OleDbCommand
NameOleDbCommand = New OleDbCommand("select first_name,
last_name, dbid from cfg_person", connstrconf)

connstrconf.Open()
NameDataReader = NameOleDbCommand.ExecuteReader()
Do While (NameDataReader.Read())
ListBox1.Items.Add(NameDataReader.GetValue(0) & " " &
NameDataReader.GetValue(1))
ListBox1.datavaluefield = NameDataReader.GetValue(2)
Loop

NameDataReader.Close()
connstrconf.Close()
End Sub

Sep 20 '06 #3
datavaluefield is supposed to be set to the name of the field. Your code
assigns to it the value of the field. And anyway, datavaluefield is used
only in databinding and you are not using any databinding, you are adding
items programatically.

You should do something like

ListBox1.Items.Add(New ListItem (NameDataReader.GetValue(0) & " " &
NameDataReader.GetValue(1), NameDataReader.GetValue(2)))

--
Eliyahu Goldin,
Software Developer & Consultant
Microsoft MVP [ASP.NET]
"l7alabeh" <l7******@gmail.comwrote in message
news:11*********************@k70g2000cwa.googlegro ups.com...
This is the code:

Sub ListBoxBind()

connstrconf.ConnectionString = strcnnconf

Dim NameDataReader As OleDbDataReader
Dim NameOleDbCommand As OleDbCommand
NameOleDbCommand = New OleDbCommand("select first_name,
last_name, dbid from cfg_person", connstrconf)

connstrconf.Open()
NameDataReader = NameOleDbCommand.ExecuteReader()
Do While (NameDataReader.Read())
ListBox1.Items.Add(NameDataReader.GetValue(0) & " " &
NameDataReader.GetValue(1))
ListBox1.datavaluefield = NameDataReader.GetValue(2)
Loop

NameDataReader.Close()
connstrconf.Close()
End Sub

Sep 20 '06 #4
Thank you
It worked!!

Sep 20 '06 #5

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

Similar topics

0
by: Mechain Marc | last post by:
In one of my logfiles I have quite repeatedly the following message: InnoDB: Warning: using a partial-field key prefix in search What does this warning mean ? Regards, Marc Mechain Atos...
4
by: Andy Weinmann | last post by:
I need to make a form through which I can edit the information for companies. I used a form in which the textboxes read from different columns from a listbox to display the information for a...
2
by: Matt Sawyer | last post by:
Hi, I'm attempting to do a drag and drop operation from one listbox to another. I have my listboxes setup with SelectionMode = MultiExtended so that I can use the shift key, cntrl key, etc. to...
1
by: Josema | last post by:
Hi to all, I have a class (persons) that derives from collection base: and another class (person) with this properties: -ID -Name When i have complete filled the object Persons with all...
1
by: Zack Sessions | last post by:
I am trying to implement a ListBox control in VB.NET. I am using the sample code right from the online help, but I am stuck on simply declaring a list item variable. The datatype ListItem simply...
3
by: Ciara9 | last post by:
I am having problems trying to update a field in a database using a field in a form. I currently have two fields, Today and Tomorrow in a table named Date. The Today field automatically defaults to...
3
by: Mufasa | last post by:
Is there any real difference between using a hidden field and using a label that is not visible. My thought being that I could leave the labels visible while testing but make them invisible once...
3
by: =?Utf-8?B?UGF1bA==?= | last post by:
probably an easy way to do this but in the code behind I could not see how to get the first and last data value field of a dropdown listbox. I have the data value field being populated with a...
7
by: ieda | last post by:
I want to display information when value in listbox selected. Below is my code:- This code to get value option in listbox <? $query = "select courseTitle from training where startDate > NOW()...
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:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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?
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
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...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.