Solved

Adding items to a drop down in VB.net

Posted on 2008-10-29
4
1,018 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

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

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

User art_snob (http://www.experts-exchange.com/M_6114203.html) encountered strange behavior of Android Web browser on his Mobile Web site. It took a while to find the true cause. It happens so, that the Android Web browser (at least up to OS ver. 2.…
A long time ago (May 2011), I have written an article showing you how to create a DLL using Visual Studio 2005 to be hosted in SQL Server 2005. That was valid at that time and it is still valid if you are still using these versions. You can still re…
Established in 1997, Technology Architects has become one of the most reputable technology solutions companies in the country. TA have been providing businesses with cost effective state-of-the-art solutions and unparalleled service that is designed…
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

786 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