473,591 Members | 2,842 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

add items to listbox inside a codebehind page returns error - Type 'ListItem' is not defined.

Hi,

I'm trying to add a default item to my listbox but when I do it tells me
that it's not defined, could someone tell me the syntax I need to use to get
the listbox control to display a default item?

I have tried the following:

lstStates.Items .Insert(0, new ListItem("By State","0"))

ME.lstStates.It ems.Insert(0, new ListItem("By State","0"))

Joey

Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArg s)
CategoryID = Cint(request.qu erystring("Cate goryID"))

If Not Page.IsPostBack () Then

lstStates.DataS ource = BindStates

lstStates.DataV alueField = "LocationID "

lstStates.DataT extField = "Location"

' lstStates.Items .Insert(0, new ListItem("By State","0"))

lstStates.Selec tedIndex = 0

lstStates.DataB ind()
lstCategorie.Da taSource = BindCategories

lstCategorie.Da taValueField = "CategoryID "

lstCategorie.Da taTextField = "CategoryDe sc"

'lstCategorie.I tems.Insert(0, new ListItem("By Category","0"))

lstCategorie.Se lectedIndex = 0

lstCategorie.Da taBind()
BindTheData(Cat egoryID)

End If

End Sub
Nov 18 '05 #1
3 4782
Hi Ryan,

The error happens when the page is loaded, I have the list on the page and
the listbox declared in the page. The error says Type 'ListItem' is not
defined..

What am I misssing?
Protected WithEvents lstStates As System.Web.UI.W ebControls.List Box

Protected WithEvents lstCategorie As System.Web.UI.W ebControls.List Box

Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArg s)
CategoryID = Cint(request.qu erystring("Cate goryID"))

If Not Page.IsPostBack () Then

lstStates.DataS ource = BindStates

lstStates.DataV alueField = "LocationID "

lstStates.DataT extField = "Location"

' lstStates.Items .Insert(0, new ListItem("By State","0"))

lstStates.Selec tedIndex = 0

lstStates.DataB ind()
lstCategorie.Da taSource = BindCategories

lstCategorie.Da taValueField = "CategoryID "

lstCategorie.Da taTextField = "CategoryDe sc"

lstCategorie.It ems.Insert(0, new ListItem("By Category","0"))

lstCategorie.Se lectedIndex = 0

lstCategorie.Da taBind()
BindTheData(Cat egoryID)

End If

End Sub

"Ryan Riddell" <Ry*********@di scussions.micro soft.com> wrote in message
news:C1******** *************** ***********@mic rosoft.com...
It looks like everything is working just fine. I did the following:
LB.Items.Add(Ne w ListItem("Field 03 - Field04", "Field03 - Field04"))
LB.Items.Add(Ne w ListItem("Field 05 - Field06", "Field05 - Field06"))
LB.Items.Insert (0, New ListItem("RYAN" ))

And it worked just fine. What line is the error on? What "isn't defined"? You do have the listbox defined on the .aspx page right? Or at
least added to the page at some point?
-Ryan

"Joey" wrote:
Hi,

I'm trying to add a default item to my listbox but when I do it tells me
that it's not defined, could someone tell me the syntax I need to use to get the listbox control to display a default item?

I have tried the following:

lstStates.Items .Insert(0, new ListItem("By State","0"))

ME.lstStates.It ems.Insert(0, new ListItem("By State","0"))

Joey

Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArg s)
CategoryID = Cint(request.qu erystring("Cate goryID"))

If Not Page.IsPostBack () Then

lstStates.DataS ource = BindStates

lstStates.DataV alueField = "LocationID "

lstStates.DataT extField = "Location"

' lstStates.Items .Insert(0, new ListItem("By State","0"))

lstStates.Selec tedIndex = 0

lstStates.DataB ind()
lstCategorie.Da taSource = BindCategories

lstCategorie.Da taValueField = "CategoryID "

lstCategorie.Da taTextField = "CategoryDe sc"

'lstCategorie.I tems.Insert(0, new ListItem("By Category","0"))

lstCategorie.Se lectedIndex = 0

lstCategorie.Da taBind()
BindTheData(Cat egoryID)

End If

End Sub

Nov 18 '05 #2
Are you sure you have a reference System.Web.UI.W ebControls? I notice that
you're using the fully qualified name on your listbox declarations but not
on the ListItem declarations.

Dale Preston
MCAD, MCSE, MCDBA

"Joey" <jo**********@d igital.com> wrote in message
news:up******** ******@tk2msftn gp13.phx.gbl...
Hi Ryan,

The error happens when the page is loaded, I have the list on the page and
the listbox declared in the page. The error says Type 'ListItem' is not
defined..

What am I misssing?
Protected WithEvents lstStates As System.Web.UI.W ebControls.List Box

Protected WithEvents lstCategorie As System.Web.UI.W ebControls.List Box

Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArg s)
CategoryID = Cint(request.qu erystring("Cate goryID"))

If Not Page.IsPostBack () Then

lstStates.DataS ource = BindStates

lstStates.DataV alueField = "LocationID "

lstStates.DataT extField = "Location"

' lstStates.Items .Insert(0, new ListItem("By State","0"))

lstStates.Selec tedIndex = 0

lstStates.DataB ind()
lstCategorie.Da taSource = BindCategories

lstCategorie.Da taValueField = "CategoryID "

lstCategorie.Da taTextField = "CategoryDe sc"

lstCategorie.It ems.Insert(0, new ListItem("By Category","0"))

lstCategorie.Se lectedIndex = 0

lstCategorie.Da taBind()
BindTheData(Cat egoryID)

End If

End Sub

"Ryan Riddell" <Ry*********@di scussions.micro soft.com> wrote in message
news:C1******** *************** ***********@mic rosoft.com...
It looks like everything is working just fine. I did the following:
LB.Items.Add(Ne w ListItem("Field 03 - Field04", "Field03 - Field04"))
LB.Items.Add(Ne w ListItem("Field 05 - Field06", "Field05 - Field06"))
LB.Items.Insert (0, New ListItem("RYAN" ))

And it worked just fine. What line is the error on? What "isn't defined"? You do have the listbox defined on the .aspx page right? Or at
least added to the page at some point?

-Ryan

"Joey" wrote:
Hi,

I'm trying to add a default item to my listbox but when I do it tells me that it's not defined, could someone tell me the syntax I need to use
to get the listbox control to display a default item?

I have tried the following:

lstStates.Items .Insert(0, new ListItem("By State","0"))

ME.lstStates.It ems.Insert(0, new ListItem("By State","0"))

Joey

Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArg s)
CategoryID = Cint(request.qu erystring("Cate goryID"))

If Not Page.IsPostBack () Then

lstStates.DataS ource = BindStates

lstStates.DataV alueField = "LocationID "

lstStates.DataT extField = "Location"

' lstStates.Items .Insert(0, new ListItem("By State","0"))

lstStates.Selec tedIndex = 0

lstStates.DataB ind()
lstCategorie.Da taSource = BindCategories

lstCategorie.Da taValueField = "CategoryID "

lstCategorie.Da taTextField = "CategoryDe sc"

'lstCategorie.I tems.Insert(0, new ListItem("By Category","0"))

lstCategorie.Se lectedIndex = 0

lstCategorie.Da taBind()
BindTheData(Cat egoryID)

End If

End Sub


Nov 18 '05 #3
Sorry for the delay, I couldn't post yesterday for no apparent reason.

Try what Dale said. If that doesn't work, try doing this order:

lstCategorie.Da taBind()
lstCategorie.It ems.Insert(0, new ListItem("By Category","0"))
lstCategorie.Se lectedIndex = 0

That is bind the data, then try and add the new ListItem.

"Joey" wrote:
Hi Ryan,

The error happens when the page is loaded, I have the list on the page and
the listbox declared in the page. The error says Type 'ListItem' is not
defined..

What am I misssing?
Protected WithEvents lstStates As System.Web.UI.W ebControls.List Box

Protected WithEvents lstCategorie As System.Web.UI.W ebControls.List Box

Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArg s)
CategoryID = Cint(request.qu erystring("Cate goryID"))

If Not Page.IsPostBack () Then

lstStates.DataS ource = BindStates

lstStates.DataV alueField = "LocationID "

lstStates.DataT extField = "Location"

' lstStates.Items .Insert(0, new ListItem("By State","0"))

lstStates.Selec tedIndex = 0

lstStates.DataB ind()
lstCategorie.Da taSource = BindCategories

lstCategorie.Da taValueField = "CategoryID "

lstCategorie.Da taTextField = "CategoryDe sc"

lstCategorie.It ems.Insert(0, new ListItem("By Category","0"))

lstCategorie.Se lectedIndex = 0

lstCategorie.Da taBind()
BindTheData(Cat egoryID)

End If

End Sub

"Ryan Riddell" <Ry*********@di scussions.micro soft.com> wrote in message
news:C1******** *************** ***********@mic rosoft.com...
It looks like everything is working just fine. I did the following:
LB.Items.Add(Ne w ListItem("Field 03 - Field04", "Field03 - Field04"))
LB.Items.Add(Ne w ListItem("Field 05 - Field06", "Field05 - Field06"))
LB.Items.Insert (0, New ListItem("RYAN" ))

And it worked just fine. What line is the error on? What "isn't

defined"? You do have the listbox defined on the .aspx page right? Or at
least added to the page at some point?

-Ryan

"Joey" wrote:
Hi,

I'm trying to add a default item to my listbox but when I do it tells me
that it's not defined, could someone tell me the syntax I need to use to get the listbox control to display a default item?

I have tried the following:

lstStates.Items .Insert(0, new ListItem("By State","0"))

ME.lstStates.It ems.Insert(0, new ListItem("By State","0"))

Joey

Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArg s)
CategoryID = Cint(request.qu erystring("Cate goryID"))

If Not Page.IsPostBack () Then

lstStates.DataS ource = BindStates

lstStates.DataV alueField = "LocationID "

lstStates.DataT extField = "Location"

' lstStates.Items .Insert(0, new ListItem("By State","0"))

lstStates.Selec tedIndex = 0

lstStates.DataB ind()
lstCategorie.Da taSource = BindCategories

lstCategorie.Da taValueField = "CategoryID "

lstCategorie.Da taTextField = "CategoryDe sc"

'lstCategorie.I tems.Insert(0, new ListItem("By Category","0"))

lstCategorie.Se lectedIndex = 0

lstCategorie.Da taBind()
BindTheData(Cat egoryID)

End If

End Sub


Nov 18 '05 #4

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

Similar topics

2
9230
by: Mark Hansen | last post by:
I'm trying to convert some schema creation scripts that were used on MS SQL Server to DB2 (v8.2) and have a problem with the following select statement (snippet) used for a view: SELECT col1, col2, timestamp-col1, TO_CHAR(timestamp-col1, 'HH24') FROM ...
1
2577
by: Chuck Haeberle | last post by:
We have need to share functionality across all of our application web pages, so we decided to subclass from System.Web.UI.Page. When we create a new aspx, the Visual Studio designer automatically puts in the codebehind, as such: public class testsubclass : System.Web.UI.Page We change this to be: public class testsubclass : OurProject.Library.BaseWebPage Which is defined as:
2
1304
by: TJS | last post by:
What doe sthis mean "Type not defined" when pointing to 'Protected with events ' line in codebehind ? ======================================== Public Class dispCalendar Inherits System.Web.UI.Page Protected WithEvents myCalendar As popUpCalendar '<==error here
0
893
by: Fred Blum | last post by:
I've created a custom tru Add User Control, the control is present in my Toolbox and shows up when placed on the Form in the Designer. However if i try to run the form i get the error Type MyProject.MyControl not defined. It must be something simple that this newbie is missing. TIA, Fred
1
2974
by: Jay | last post by:
Hi, I have been working on ASP.NET 2.0. When I was trying to work with one of the master pages, I used some classes (.vb files) in App_code directory. When the application is run, it gives me the following error. BC40056: Namespace or type specified in the Imports 'XXXX' doesn't contain any public member or cannot be found. Make sure the namespace or the type is defined and contains at least one public member. Make sure the imported...
1
1738
by: zoneal | last post by:
Hi I am trying to get html response from a web server for a given URL . I have written following code. Imports System.Net Imports System.IO Dim objRequest As HTTPWebRequest = WebRequest.Create("http://www.google.com")
0
1469
by: SimonZ | last post by:
If I have gridView and one of the columns is template cpolumn, where I have listBox in edit mode: <asp:TemplateField> <HeaderTemplate>CategorName:</HeaderTemplate> <ItemTemplate> <asp:Label runat="server" text='<%# Eval("CategoryName")%>'></asp:Label> </ItemTemplate> <EditItemTemplate>
5
4747
by: jrobbins | last post by:
public IEnumerable<AuthorizationObjectClass> GetEmployeeNoAuthorizations(SqlInt32 PersonnelNumber) { DataSet ds; AuthorizationObjectClass auth = new AuthorizationObjectClass(); try { //EmployeeObjectClass Emp = new EmployeeObjectClass(); Emp.PersonnelNumber = PersonnelNumber; ds = data.GetNotSelectedAuthorizations(Emp); ...
6
8354
by: kucheravy | last post by:
Hi, everybody. I have this problem. When I put a <asp:ListBox on a web page and populate the data in the page Page_Load event the ViewState for the control is saved and loaded (after postback) correctly. In other words the Items property of the ListBox is populated from the ViewState after the postback. However if I put this ListBox inside a UserControl, expose the Items list, and populate it with the data in the same manner (in the page...
0
8362
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
7992
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
5732
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
5400
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
3850
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...
0
3891
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2378
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
1
1465
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
1199
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.