Solved

Adding items to a drop down in VB.net

Posted on 2008-10-29
4
1,016 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
ID: 22832946
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
ID: 22833121
Ah I get it...thx

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

Expert Comment

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

Author Comment

by:bdb12
ID: 22833194
Ah thx again
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

ASP.Net to Oracle Connectivity Recently I had to develop an ASP.NET application connecting to an Oracle database.As I am doing it first time ,I had to solve several problems. This article will help to such developers  to develop an ASP.NET client…
IntroductionWhile developing web applications, a single page might contain many regions and each region might contain many number of controls with the capability to perform  postback. Many times you might need to perform some action on an ASP.NET po…
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…
Internet Business Fax to Email Made Easy - With  eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, f…

912 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

16 Experts available now in Live!

Get 1:1 Help Now