Solved

Adding items to a drop down in VB.net

Posted on 2008-10-29
4
1,014 Views
Last Modified: 2012-05-05
Using vs 2008. On a web app I have 2 drop downs....

When a value in the first ddl is selected it autopostbacks and populates the 2nd ddl. This works fine

However I just want to add an item at the top of the 2nd ddl saying "please choose..." with the following code

DropDownList2.Items.Insert(0, "please choose...")

I have place this code in the DropDownList1_SelectedIndexChanged function......It compiles but doesnt work

Any ideas? Thx
0
Comment
Question by:bdb12
  • 2
  • 2
4 Comments
 
LVL 18

Accepted Solution

by:
David Robitaille earned 500 total points
Comment Utility
i made it that way
make sure to set  AppendDataBoundItems="True" to the dropdown list

    Protected Sub DropDownListCategory_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs)
 

        Dim DropDownListCategory As DropDownList = CType(sender, DropDownList)

        Dim DropDownListSubCategory As DropDownList = CType(FormViewOption.FindControl("SubCategory"), DropDownList)

        DropDownListSubCategory.Items.Clear()

        DropDownListSubCategory.Items.Add(New ListItem("(Select a Sub-Category)", ""))

        DropDownListSubCategory.SelectedValue = ""
 

        If DropDownListCategory.SelectedValue = "" Then

            DropDownListSubCategory.Enabled = False

        Else

            CType(FormViewOption.FindControl("ObjectDataSourceSubCategory"), ObjectDataSource).Select()

            DropDownListSubCategory.DataBind()

            DropDownListSubCategory.Enabled = True

        End If

        

    End Sub

Open in new window

0
 

Author Comment

by:bdb12
Comment Utility
Ah I get it...thx

What do u mean u made it that way?
0
 
LVL 18

Expert Comment

by:David Robitaille
Comment Utility
probably my bad english...
I mean "I did it that way in a previous project"
0
 

Author Comment

by:bdb12
Comment Utility
Ah thx again
0

Featured Post

What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

Join & Write a Comment

Just a quick little trick I learned recently.  Now that I'm using jQuery with abandon in my asp.net applications, I have grown tired of the following syntax:      (CODE) I suppose it just offends my sense of decency to put inline VBScript on a…
Creating an analog clock UserControl seems fairly straight forward.  It is, after all, essentially just a circle with several lines in it!  Two common approaches for rendering an analog clock typically involve either manually calculating points with…
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.
This tutorial demonstrates a quick way of adding group price to multiple Magento products.

763 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now