Solved

How to pass data from Listbox to a textbox

Posted on 2012-04-04
8
317 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 

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
 
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

Application Discovery Service in AWS

In the era of the cloud, customers migrating away from their existing on-premise infrastructure. This requires lots of planning, strategies, and effort to identify their existing resources and determine how best to migrate.  Datacenter migrations happen in four phases -

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

ASP.Net to Oracle Connectivity Recently I had to develop an ASP.NET application connecting to an Oracle database.As I am doing it first time ,I had to solve several problems. This article will help to such developers  to develop an ASP.NET client…
More often than not, we developers are confronted with a need: a need to make some kind of magic happen via code. Whether it is for a client, for the boss, or for our own personal projects, the need must be satisfied. Most of the time, the Framework…
Monitoring a network: why having a policy is the best policy? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the enormous benefits of having a policy-based approach when monitoring medium and large networks. Software utilized in this v…
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…

623 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