Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > listbox datavaluefield and datatextfield

Reply
Thread Tools

listbox datavaluefield and datatextfield

 
 
tshad
Guest
Posts: n/a
 
      05-10-2005
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


 
Reply With Quote
 
 
 
 
=?Utf-8?B?UGl5dXNoIFRoYWt1cmlh?=
Guest
Posts: n/a
 
      05-10-2005
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
>
>
>

 
Reply With Quote
 
 
 
 
=?Utf-8?B?UGF0cmljay5PLklnZQ==?=
Guest
Posts: n/a
 
      05-10-2005
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
>
>
>

 
Reply With Quote
 
tshad
Guest
Posts: n/a
 
      05-10-2005
"tshad" <> wrote in message
news:...
> 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
>
>



 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Using the DataTextField and DataValue Field in a ListBox l7alabeh ASP .Net 4 09-20-2006 11:43 AM
Listbox DataValueField Gerald ASP .Net Web Controls 0 06-23-2005 04:42 AM
Listbox DataValueField Gerald ASP .Net 0 06-22-2005 04:18 PM
Dropdownlist,DataTextField,DataValueField ? Sam ASP .Net 1 02-18-2005 11:52 AM
DropdownList, DataValueField, DataTextField and Custom Collections.. Parodi Development ASP .Net 0 09-10-2004 06:29 PM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57