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.WebControls.ListBox
Protected WithEvents lstCategorie As System.Web.UI.WebControls.ListBox
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs)
CategoryID = Cint(request.querystring("CategoryID"))
If Not Page.IsPostBack() Then
lstStates.DataSource = BindStates
lstStates.DataValueField = "LocationID"
lstStates.DataTextField = "Location"
' lstStates.Items.Insert(0, new ListItem("By State","0"))
lstStates.SelectedIndex = 0
lstStates.DataBind()
lstCategorie.DataSource = BindCategories
lstCategorie.DataValueField = "CategoryID"
lstCategorie.DataTextField = "CategoryDesc"
lstCategorie.Items.Insert(0, new ListItem("By Category","0"))
lstCategorie.SelectedIndex = 0
lstCategorie.DataBind()
BindTheData(CategoryID)
End If
End Sub
"Ryan Riddell" <Ry*********@discussions.microsoft.com> wrote in message
news:C1**********************************@microsof t.com...
It looks like everything is working just fine. I did the following:
LB.Items.Add(New ListItem("Field03 - Field04", "Field03 - Field04"))
LB.Items.Add(New ListItem("Field05 - 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.Items.Insert(0, new ListItem("By State","0"))
Joey
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs)
CategoryID = Cint(request.querystring("CategoryID"))
If Not Page.IsPostBack() Then
lstStates.DataSource = BindStates
lstStates.DataValueField = "LocationID"
lstStates.DataTextField = "Location"
' lstStates.Items.Insert(0, new ListItem("By State","0"))
lstStates.SelectedIndex = 0
lstStates.DataBind()
lstCategorie.DataSource = BindCategories
lstCategorie.DataValueField = "CategoryID"
lstCategorie.DataTextField = "CategoryDesc"
'lstCategorie.Items.Insert(0, new ListItem("By Category","0"))
lstCategorie.SelectedIndex = 0
lstCategorie.DataBind()
BindTheData(CategoryID)
End If
End Sub