473,835 Members | 1,872 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 4796
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
9244
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
2592
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
1317
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
902
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
2987
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
1753
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
1483
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
4757
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
8365
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
9810
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
9653
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
10815
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
10562
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,...
0
10236
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
6968
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
5639
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
5805
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4434
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

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.