Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Adding items to a drop down in VB.net

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

Veeam Task Manager for Hyper-V

Task Manager for Hyper-V provides critical information that allows you to monitor Hyper-V performance by displaying real-time views of CPU and memory at the individual VM-level, so you can quickly identify which VMs are using host resources.

Question has a verified solution.

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

More often than not, we developers are confronted with a need: a need to make some kind of magic happen via code. Whether it is for a client, for the boss, or for our own personal projects, the need must be satisfied. Most of the time, the Framework…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an anti-spam), the admin…
Is your data getting by on basic protection measures? In today’s climate of debilitating malware and ransomware—like WannaCry—that may not be enough. You need to establish more than basics, like a recovery plan that protects both data and endpoints.…

783 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