473,403 Members | 2,293 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,403 software developers and data experts.

ListBox?

Consider the following code that populates a ListBox:

<script runat="server">
Sub Page_Load(ByVal obj As Object, ByVal ea As EventArgs)
If Not (Page.IsPostBack) Then
'create an array of colors
Dim arrColors() As String = {"red", "blue", "green"}

lbColors.DataSource = arrColors
lbColors.SelectedIndex = 0
End If
Page.DataBind()
End Sub
</script>

<form runat="server">
<asp:ListBox id="lbColors" AutoPostBack="true" SelectionMode="single"
runat="server"/>
<asp:Label id="lblMessage" Text=<%# lbColors.SelectedItem.Text %>
runat="server"/>
</form>

The above code works fine as expected & populates the ListBox with the
different colors listed in the array one after the other i.e. the
ListBox looks like this:

red
blue
green
yellow

No problem till here but if the variable "arrColors" is declared as
just a string & NOT as a string array as shown in the above code & it
is assigned a value, say, "yellow" i.e. the "Dim arrColors()......"
line in the above code is replaced by

Dim arrColors As String = "yellow"

then the ListBox looks like this (keeping the rest of the code shown
above as it is):

y
e
l
l
o
w

Why so?

Thanks,

Arpan

Aug 1 '06 #1
2 1008
Hi,
A string object is a collection of unicode characters that can be enumerated
over/through so I guess that if assigned directly as a datasource it is
interpreted as such. To add a single string you'd need to (apologies if you
know already) :

Dim arrColors As String = "yellow"
lbColors.Items.Add(arrColors)

Chris

"Arpan" wrote:
Consider the following code that populates a ListBox:

<script runat="server">
Sub Page_Load(ByVal obj As Object, ByVal ea As EventArgs)
If Not (Page.IsPostBack) Then
'create an array of colors
Dim arrColors() As String = {"red", "blue", "green"}

lbColors.DataSource = arrColors
lbColors.SelectedIndex = 0
End If
Page.DataBind()
End Sub
</script>

<form runat="server">
<asp:ListBox id="lbColors" AutoPostBack="true" SelectionMode="single"
runat="server"/>
<asp:Label id="lblMessage" Text=<%# lbColors.SelectedItem.Text %>
runat="server"/>
</form>

The above code works fine as expected & populates the ListBox with the
different colors listed in the array one after the other i.e. the
ListBox looks like this:

red
blue
green
yellow

No problem till here but if the variable "arrColors" is declared as
just a string & NOT as a string array as shown in the above code & it
is assigned a value, say, "yellow" i.e. the "Dim arrColors()......"
line in the above code is replaced by

Dim arrColors As String = "yellow"

then the ListBox looks like this (keeping the rest of the code shown
above as it is):

y
e
l
l
o
w

Why so?

Thanks,

Arpan

Aug 1 '06 #2
>so I guess that if assigned directly as a datasource it is
>interpreted as such
Since you are saying that your response is just a "guess", can I
conclude that you aren't 100% sure about your answer? I did prefer
getting a concrete answer to my post, my dear friend!

Thanks,

Regards,

Arpan
Chris K wrote:
Hi,
A string object is a collection of unicode characters that can be enumerated
over/through so I guess that if assigned directly as a datasource it is
interpreted as such. To add a single string you'd need to (apologies if you
know already) :

Dim arrColors As String = "yellow"
lbColors.Items.Add(arrColors)

Chris

"Arpan" wrote:
Consider the following code that populates a ListBox:

<script runat="server">
Sub Page_Load(ByVal obj As Object, ByVal ea As EventArgs)
If Not (Page.IsPostBack) Then
'create an array of colors
Dim arrColors() As String = {"red", "blue", "green"}

lbColors.DataSource = arrColors
lbColors.SelectedIndex = 0
End If
Page.DataBind()
End Sub
</script>

<form runat="server">
<asp:ListBox id="lbColors" AutoPostBack="true" SelectionMode="single"
runat="server"/>
<asp:Label id="lblMessage" Text=<%# lbColors.SelectedItem.Text %>
runat="server"/>
</form>

The above code works fine as expected & populates the ListBox with the
different colors listed in the array one after the other i.e. the
ListBox looks like this:

red
blue
green
yellow

No problem till here but if the variable "arrColors" is declared as
just a string & NOT as a string array as shown in the above code & it
is assigned a value, say, "yellow" i.e. the "Dim arrColors()......"
line in the above code is replaced by

Dim arrColors As String = "yellow"

then the ListBox looks like this (keeping the rest of the code shown
above as it is):

y
e
l
l
o
w

Why so?

Thanks,

Arpan
Aug 2 '06 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

17
by: amber | last post by:
Hello. Can someone tell me what I may be doing wrong here? I'm using the code (lboxRP is a listbox): Dim newRPindex As Integer newRPindex = Me.lboxRP.FindString(RP)...
3
by: Paul T. Rong | last post by:
I have a listbox (of product names) control on my form. I want to pass the selected item (a product name) to a subform, and the product unitprice should apear automatically next to the product name...
8
by: Oddball | last post by:
Ok - I have a ListBox control and I'm ready to write my own DrawItem event handler. What I want to draw as the item is another control. I have created a user control that I would like to list in...
2
by: collie | last post by:
Hi, I have 2 listboxes. The first gets populated from the db as soon as the page loads. The second listbox get populated based on the user's selection from the first listbox. However,...
6
by: Chris Leuty | last post by:
I am populating a multiselect Listbox from a dataset, with the content of the listbox filled by one table, and the selections determined from another table. So far, I have been keeping the dataset...
1
by: yamne | last post by:
I have a problem. When I click in edit datagrid button I show two listbox and two button. I use two button to move data between two listbox. My problem is that I can't call the listbox in the...
7
by: Dave | last post by:
Hi all, After unsuccessfully trying to make my own dual listbox control out of arraylists, I decided to look for a 3rd party control. I've looked for over a week now and can't find anything but...
3
by: Ali Chambers | last post by:
Hi, I have created a listbox called "dtlist1" on my VB.NET form. I call a procedure as follows: Private Sub openfile(flname As String) dtlist1.Items.Clear() etc..
1
by: Sunray | last post by:
I have a form called the sales form and i have 2 sets of listboxes So what happens is. i add items form the bottom set of list boxes which are bound to a data base to the top set of list boxes which...
5
by: Academia | last post by:
(If you've seen this in the drawing NG, sorry. I inadvertently sent it there.) I have a listbox populated with Objects. The Class has a String field that ToString returns. I assume that...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.