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

listbox datavaluefield and datatextfield

How do I get to the datatextfield of listbox?

I can get the the datavaluefield using the selectedvalue. I want to get the
text portion of the listbox that the user selected.

Thanks,

Tom
Nov 19 '05 #1
3 6538
Hi,

In a list box the user can select single or multiple values. Below is the
code given for reading the multiple text values of the listbox in a string
seperated by commas.

Dim lCtr
Dim strText as String

If listBox.Items.Count > 0 Then
For lCtr = 1 To lstBox.Items.Count
If istBox.Items(lCtr - 1).Selected = True Then
strText = lstBox.Items(lCtr - 1).Value
' Can have some code to append commas.......
End If
Next
End If

strText would be a string consistes od comma. You may also use the String
Builder class, if you want to optimise the string.

Please let me know if this is what you were looking for.....

Thanks and Regards,

Piyush
"tshad" wrote:
How do I get to the datatextfield of listbox?

I can get the the datavaluefield using the selectedvalue. I want to get the
text portion of the listbox that the user selected.

Thanks,

Tom

Nov 19 '05 #2
Tom try using :-
" ddlNamesList.SelectedItem.Text"
e.g ddlNamesList being ur listBox
Patrick
"tshad" wrote:
How do I get to the datatextfield of listbox?

I can get the the datavaluefield using the selectedvalue. I want to get the
text portion of the listbox that the user selected.

Thanks,

Tom

Nov 19 '05 #3
"tshad" <tf*@dslextreme.com> wrote in message
news:uA*************@TK2MSFTNGP12.phx.gbl...
How do I get to the datatextfield of listbox?

I can get the the datavaluefield using the selectedvalue. I want to get the text portion of the listbox that the user selected.
Figured it out.

listbox.SelectedItem.text

It is interested that for the value you can use either:

listbox.SelectedValue or listbox.SelectedItem.Value

I'm surprised that there isn't a listbox.SelectedText also (to be
consistant).

Tom
Thanks,

Tom

Nov 19 '05 #4

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

Similar topics

3
by: Paul W | last post by:
I am populating listbox with a datreader. DateReader sqlcommand is dynamic, based on several user selections Listbox DataValueField is set to the tables primary key Listbox DataTextField is...
1
by: Ray Valenti | last post by:
I have a ASP listbox that I am trying to populate with two fields, one for display (Category) and one to store (ID) as the selected item. I can successfully populate and view the list. How ever...
4
by: Moe Sizlak | last post by:
Hi There, I am trying to return the value of a listbox control that is included as a user control, I can return the name of the control but I can't access the integer value of the selected item,...
3
by: Joey | last post by:
Hi, I'm trying to add a default item to my listbox but when I do it tells me that it's not defined, could someone tell me the syntax I need to use to get the listbox control to display a default...
5
by: Lie | last post by:
Hi all, I have problem in getting selectedindex of multiple listbox selection in a datagrid. I have a listbox with multiple selection mode inside datagrid. In Edit mode, I need to get back all...
0
by: Gerald | last post by:
Hi, Is it possible to do some action on the value that will be the DataValueField of a listbox? I have a listbox with a list of item. But I would like to encode the value ID that the client...
8
by: Steve Schroeder | last post by:
For some reason I cannot get the OnSelectedIndexChanged event to fire for a listbox I have on a page. I'm able to populate the listbox with data from a stored procedure, but cannot trigger the...
6
by: Sparky Arbuckle | last post by:
The code below works to an extent. The problem with it is that no matter which item is selected, the first one in the list is always the item that gets added/removed. How can I alleviate this...
4
by: Marcos Beccar Varela | GamaCom Argentina | last post by:
Hello Everyone. I need to use a gridview, that when I use the Update command one of the colums, instead of showing a textbox where the user can write, I need a combobox (listobx), where there are...
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
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
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...
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.