473,748 Members | 9,641 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

lstListBox.Sele ctedItem cannot be converted to 'String'

How can I convert[ListBox.Selecte dItem] 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.Selecte dItem)
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.Selecte dItem ---
gets a blue squiggly line under ListBox.Selecte dItem
My 2nd attempt: --- Label1.Text = ListBox.Selecte dItem --- gets a blue
squiggly line under ListBox.Selecte dItem

Both result in the following error: Value of type
'System.Web.UI. WebControls.Lis tItem' cannot be converted to 'String'.
May 3 '07 #1
2 7089
Just FYI I was give the solution Label1.Text = ListBox.Text

"Tracey" <wp***@gte.netw rote in message
news:%2******** ********@TK2MSF TNGP04.phx.gbl. ..
How can I convert[ListBox.Selecte dItem] 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.Selecte dItem)
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.Selecte dItem ---
gets a blue squiggly line under ListBox.Selecte dItem
My 2nd attempt: --- Label1.Text = ListBox.Selecte dItem --- gets a blue
squiggly line under ListBox.Selecte dItem

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


May 3 '07 #2
On May 3, 10:31 am, "Tracey" <w...@gte.netwr ote:
How can I convert[ListBox.Selecte dItem] 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.Selecte dItem)
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.Selecte dItem ---
gets a blue squiggly line under ListBox.Selecte dItem
My 2nd attempt: --- Label1.Text = ListBox.Selecte dItem --- gets a blue
squiggly line under ListBox.Selecte dItem

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

ListBox.Selecte dItem.ToString( )

May 3 '07 #3

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

Similar topics

8
5478
by: baustin75 | last post by:
Posted: Mon Oct 03, 2005 1:41 pm Post subject: cannot mail() in ie only when debugging in php designer 2005 -------------------------------------------------------------------------------- Hello, I have a very simple problem but cannot seem to figure it out. I have a very simple php script that sends a test email to myself. When I debug it in PHP designer, it works with no problems, I get the test email. If
1
15361
by: gordon | last post by:
Hi I have a combo box that my application uses to select an item for a regression function. I would like to convert the selected item to a string value and use this value later in my code. I have used private string charVal;
0
1989
by: huobazi | last post by:
I have many dropdownlist controls in my ascx (and use LoadControl in a aspx fiel) file,so i write a method "InitList(DropDownList list,string strsql,string TextField,string ValueField)" but when i want to get the BigClassList.SelectedItem.Text and BigClassList.SelectedItem.Value in a button onclick method,btnSmallClassEdit_Click(....),there post an error " System.NullReferenceException: 佫¶ÔÏóÒýÓÃÉèÖõ½¶ÔÏóµÄʵÀý¡£", I Don't know the...
2
5888
by: Sean | last post by:
Hello, I have a function in C# that accepts a stored proc name and an array of parameters, and then returns a dataset, which works just fine. I have converted the function to VB: Public Shared Function GetDataSet(ByVal storedProcedure As String, ByRef parameterArray As Object()) As DataSet
7
11195
by: Ohad Asor | last post by:
Hello all, I have an ASP.NET page I've written using VS.NET2003, which have a ListBox in it. When I press a button in the form, I try to get the selected item in the list by calling ListBox.SelectedItem. And it returns null, even when I select an item. Even when I try to read the value when I get the SelectedIndexChanged event, it still doesn't give me the correct answer.
2
7213
by: Jim in Arizona | last post by:
I'm learning form an ASP.NET 1.0 book and I tried out some code that returns this error: Compiler Error Message: BC30311: Value of type 'Integer' cannot be converted to 'ASP.multiclasses_aspx.VehicleKey'. Source Error: Line 106:
1
23658
by: hangdee | last post by:
I have a DatagridviewComboBoxCell with self added object (with an id and a string field) as items to the DatagridviewComboBoxCell. Dim cboCell As New DataGridViewComboBoxCell cboCell.Items.Add(new MyObj(1,"Item 1")) cboCell.Items.Add(new MyObj(2,"Item 2")) cboCell.Items.Add(new MyObj(3,"Item 3")) But I cannot find a method from DataGridViewComboBoxCell to get back the selected MyObj in the cboCell list.
1
8591
by: rdlauer | last post by:
For some time now we've been seeing seemingly random errors thrown by an application "Padding is invalid and cannot be removed". Everything I've read about this online suggests that the machine key is different between two load-balanced servers, but this application is running on just one server. The other odd thing is that the errors come in groups. Over a short period of time (5 minutes or so) many different users will hit this error...
1
1807
by: Shimna Thomas | last post by:
In the below code, I am trying to redirect to another page, depending on the value of the selected item in the listbox;but I am getting the error : "Cannot implicitly convert type'string ' to 'bool' if (ListBox3.SelectedItem.Value = "Cno") Response.Redirect("Contact.aspx"); May i know how can i correct it?
0
8989
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8828
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9537
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
9319
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
1
6795
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
4599
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
3309
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
2780
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2213
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.