lstListBox.SelectedItem cannot be converted to 'String'

T

Tracey

How can I convert [ListBox.SelectedItem] to a string (what I thought was a
string)?
and/or
How can I assign the value of a selected item in a list box to Label1.Text?
using VB in VS2005.
Thanks, Tracey

I completed a {simple} class project that displays the value of what was
clicked in a List Box (which appears at the top of the page):
Response.Write("You clicked ")
Response.Write(ListBox.SelectedItem)
Class Project completed as designed without any error message.

But the whole page shifts/jumps down which doesn't look very elegant to me
so I created a label at the top of the page to display the value of what was
selected:
My 1st attempt: --- Label1.Text = "You clicked " : ListBox.SelectedItem ---
gets a blue squiggly line under ListBox.SelectedItem
My 2nd attempt: --- Label1.Text = ListBox.SelectedItem --- gets a blue
squiggly line under ListBox.SelectedItem

Both result in the following error: Value of type
'System.Web.UI.WebControls.ListItem' cannot be converted to 'String'.
 
L

Larry Bud

How can I convert [ListBox.SelectedItem] to a string (what I thought was a
string)?
and/or
How can I assign the value of a selected item in a list box to Label1.Text?
using VB in VS2005.
Thanks, Tracey

I completed a {simple} class project that displays the value of what was
clicked in a List Box (which appears at the top of the page):
Response.Write("You clicked ")
Response.Write(ListBox.SelectedItem)
Class Project completed as designed without any error message.

But the whole page shifts/jumps down which doesn't look very elegant to me
so I created a label at the top of the page to display the value of what was
selected:
My 1st attempt: --- Label1.Text = "You clicked " : ListBox.SelectedItem ---
gets a blue squiggly line under ListBox.SelectedItem
My 2nd attempt: --- Label1.Text = ListBox.SelectedItem --- gets a blue
squiggly line under ListBox.SelectedItem

Both result in the following error: Value of type
'System.Web.UI.WebControls.ListItem' cannot be converted to 'String'.

Should be

ListBox.SelectedItem.ToString()
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,744
Messages
2,569,482
Members
44,901
Latest member
Noble71S45

Latest Threads

Top