Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 320
  • Last Modified:

How to pass data from Listbox to a textbox

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
vcharles
Asked:
vcharles
  • 3
  • 3
  • 2
1 Solution
 
gplanaCommented:
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
 
nepaluzCommented:
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
 
vcharlesAuthor Commented:
Thank you, I will try them and get back you. How do I accomplish the same with all the rows in a  GridView?
0
Learn Veeam advantages over legacy backup

Every day, more and more legacy backup customers switch to Veeam. Technologies designed for the client-server era cannot restore any IT service running in the hybrid cloud within seconds. Learn top Veeam advantages over legacy backup and get Veeam for the price of your renewal

 
vcharlesAuthor Commented:
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
 
nepaluzCommented:
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
 
gplanaCommented:
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
 
vcharlesAuthor Commented:
It worked! Thanks!

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

Victor
0
 
gplanaCommented:
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 Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 3
  • 3
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now