Solved

How to pass data from Listbox to a textbox

Posted on 2012-04-04
8
305 Views
Last Modified: 2012-04-04
Hello,

I am using the code below to pass data from my testbox to a list box, How do I pass the data from my listbox to a textbox separated by a (;).

C1NSN.Text = dtNSN.Rows(0).Item("NSN")
        Dim tmp() As String = C1NSN.Text.split(";")
        For i As Integer = 0 To tmp.Length - 1
            ListBox1.Items.Add(tmp(i))
         Next


Thanks,

Victor
0
Comment
Question by:vcharles
  • 3
  • 3
  • 2
8 Comments
 
LVL 15

Expert Comment

by:gplana
ID: 37805570
Try something like this:

C1NSN.Text = ""
For i = 0 to listbox.items.count-1
   C1NSN.Text = C1NSN.Text & ";" & ListBox1.Items(0).Text
next i

Open in new window


Hope it helps
0
 
LVL 17

Expert Comment

by:nepaluz
ID: 37805602
Do:
For x = 0 To LBox.Items.Count - 1
    C1NSN.Text = If(String.IsNullOrEmpty(C1NSN.Text.ToString.Trim), LBox.Items(x), C1NSN.Text & ";" & LBox.Items(x))
Next

Open in new window

0
 

Author Comment

by:vcharles
ID: 37805720
Thank you, I will try them and get back you. How do I accomplish the same with all the rows in a  GridView?
0
 

Author Comment

by:vcharles
ID: 37805786
Hi,

I tried both of them but it is still not working, the following code:

C1NSN.Text = ""
For i = 0 to listbox.items.count-1
   C1NSN.Text = C1NSN.Text & ";" & ListBox1.Items(0).Text
next i


Gives me the data of the first row multiple times, for example if my list box contains

AAAAA
BBBBBB
CCCCCC

My textbox shows:
AAAAA
AAAAA
AAAAA


The following code:

For x = 0 To LBox.Items.Count - 1
    C1NSN.Text = If(String.IsNullOrEmpty(C1NSN.Text.ToString.Trim), LBox.Items(x), C1NSN.Text & ";" & LBox.Items(x))
Next

Give me error message:

Operator '&' is not defined for types 'String' and 'System.Web.UI.WebControls.ListItem'.
0
6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

 
LVL 17

Expert Comment

by:nepaluz
ID: 37805862
get the listbox item text instead
For x = 0 To ListBox1.Items.Count - 1
    C1NSN.Text = If(String.IsNullOrEmpty(C1NSN.Text.ToString.Trim), ListBox1.Items(x).Text, C1NSN.Text & ";" & ListBox1.Items(x).Text)
Next

Open in new window

0
 
LVL 15

Accepted Solution

by:
gplana earned 500 total points
ID: 37805885
Sorry, instead of Items(0) put Items(i):

C1NSN.Text = ""
For i = 0 to listbox.items.count-1
   C1NSN.Text = C1NSN.Text & ";" & ListBox1.Items(0).Text
next i
C1NSN.Text = Mid(C1NSN.Text,2) 'This is to eliminate first ";"

Open in new window

0
 

Author Comment

by:vcharles
ID: 37805905
It worked! Thanks!

Do you know how to also do the same with a gridwiew?

Victor
0
 
LVL 15

Expert Comment

by:gplana
ID: 37806012
Happy to know it worked. Sorry, I haven't work with gridview. I suggest to open another question for this and add the code you have on this new question.
0

Featured Post

Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

The ECB site provides FX rates for major currencies since its inception in 1999 in the form of an XML feed. The files have the following format (reducted for brevity) (CODE) There are three files available HERE (http://www.ecb.europa.eu/stats/exch…
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.
This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're looking for how to monitor bandwidth using netflow or packet s…

744 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now