Solved

Adding items to a drop down in VB.net

Posted on 2008-10-29
4
1,020 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Suggested Solutions

Title # Comments Views Activity
aspx ascx, c# 7 43
Select coumns form Data table? 3 27
Concurrency Error Persistent using Data Grid View Update C# 2 30
Textbox autocomplete using jquery in asp.net 13 49
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.…
Parsing a CSV file is a task that we are confronted with regularly, and although there are a vast number of means to do this, as a newbie, the field can be confusing and the tools can seem complex. A simple solution to parsing a customized CSV fi…
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …
Are you ready to implement Active Directory best practices without reading 300+ pages? You're in luck. In this webinar hosted by Skyport Systems, you gain insight into Microsoft's latest comprehensive guide, with tips on the best and easiest way…

739 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