Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Adding items to a drop down in VB.net

Posted on 2008-10-29
4
Medium Priority
?
1,025 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 2000 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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

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…
Introduction This article shows how to use the open source plupload control to upload multiple images. The images are resized on the client side before uploading and the upload is done in chunks. Background I had to provide a way for user…
This course is ideal for IT System Administrators working with VMware vSphere and its associated products in their company infrastructure. This course teaches you how to install and maintain this virtualization technology to store data, prevent vuln…
In this brief tutorial Pawel from AdRem Software explains how you can quickly find out which services are running on your network, or what are the IP addresses of servers responsible for each service. Software used is freeware NetCrunch Tools (https…

715 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