Victor Charles
asked on
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
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
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
ASKER
Thank you, I will try them and get back you. How do I accomplish the same with all the rows in a GridView?
ASKER
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(C1 NSN.Text.T oString.Tr im), 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' .
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(C1
Next
Give me error message:
Operator '&' is not defined for types 'String' and 'System.Web.UI.WebControls
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
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
It worked! Thanks!
Do you know how to also do the same with a gridwiew?
Victor
Do you know how to also do the same with a gridwiew?
Victor
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.
Open in new window
Hope it helps