drop down menu looses initial option

L

Laura K

I have a drop down menu which has a list of subcategories and the
initial value is "please choose a Subcategory". When the user chooses a
subcategory they are taken to a new page where the drop down list shows
the selected subcategory in the menu. So far that is working.

The problem is that when the list is showing the subcategory on the
second page there are now two of that item in the list and the initial
item that should be available in the drop down is missing.

In other words in the initial drops down the user has the following
options,.


Choose a subcategory
shoes
boots
slippers

The user chooses boots

Then on the following page which is the boots subcategory the list
looks like this.

boots
boots
slippers

I would love some help. Here is the code:

---------------------------------------------------------------------------------

'The Department for which we are loading the categories

Dim BrandID As String = Request.QueryString("brandID")
Dim CategoryID As String = Request.QueryString("CategoryID")
Dim strSubCategory As String =
Request.QueryString("strSubCategory")

'choosing if it is a brand or category - each pulls from a different
database table

If Not IsPostBack Then
If Not CategoryID Is Nothing Then

list.DataSource = Catalog.GetSubCatsinCats(CategoryID)
list.DataBind()
'lblsubnav.Text = CategoryID

'If there is no subcategory in the querystring then you have the
"Please choose a subcategory" and the initial list. Otherwise you
have the selected item showing

HERE IS THE PROBLEM!

If Not strSubCategory Is Nothing Then
list.SelectedItem.Text = strSubCategory
Else
list.Items.Insert(0, "Please choose a subcategory")
End If


'repeats for brands

ElseIf Not BrandID Is Nothing Then
list.DataSource = Catalog.GetSubCatsInBrands(BrandID)
list.DataBind()
If Not strSubCategory Is Nothing Then
list.SelectedItem.Text = strSubCategory
Else
list.Items.Insert(0, "Please choose a subcategory")
End If
Else

' lblsubnav.Visible = False
list.Visible = False
' label.Visible = False

End If


End If


-----------------------------------------------------------------
 
O

OHM \( One Handed Man \)

If Not strSubCategory Is Nothing Then

list.SelectedItem.Text = strSubCategory
Else
list.Items.Insert(0, "Please choose a subcategory")
End If
 
L

Laura K

Not sure what you mean. Can you give me an idea of what the actual
correct code would be?
 
L

Laura K

OK fixed it a bit but now I have a new problem. I changed

list.SelectedItem.Text = strSubCategory
to

list.Items.Insert(0, strSubCategory)

This works fine except I get the text twice. Once on the top of the
list where the user can see it when the page loads and a second time in
the list itself where it nornally is.
 
O

OHM \( One Handed Man \)

The problem is that your sub catagory is the same name as the first item in
the list. You dont need to add this at all as far as I can see as once you
have selected the subcategory, you now have the list ( of sub categories )
that you need,so Im not sure why are you trying to add it in ?

Unless I have misunderstood you ?
 

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

No members online now.

Forum statistics

Threads
473,754
Messages
2,569,521
Members
44,995
Latest member
PinupduzSap

Latest Threads

Top