Solved

VB.NET: Change Dropdownlist DataSource on web form on the fly

Posted on 2004-10-02
1
494 Views
Last Modified: 2008-01-09
I have a dropdownlist on a web form that is already populated with values. In certain situations I want to do the following:

1. Erase the list in the dropdownlist (I'm done with it, don't need it anymore)
2. Plug in a single DataValueField and DataTextField (using values from string variables)
3. Make the plugged Text/Value appear in the dropdownlist
4. Select it.

How do I do it in VB.NET?
0
Comment
Question by:rgrimm
1 Comment
 
LVL 7

Accepted Solution

by:
jackiechen858 earned 250 total points
Comment Utility

if you want it in server side:

2.  
        ddl.Items.Add(New ListItem("text", "value"))
        ddl.Items.Insert(the index you want , New ListItem("text", "value"))
3. if you do 2, it will appear in the dropdownlist.

4.         ddl.SelectedIndex = the item's index;
if you use Add, the index should be ddl.Items.Count -1.


if you want in client side:

      <script lang="JavaScript">
      <!--
            function addItem( )
            {
                                       len=document.all.ddl.options.length;
                                       document.all.ddl.options[len] =new Option("text", "value", false, false);
                                       document.all.ddl.selectedIndex=len;
            }
            
      //-->
      </script>



0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
Please explain "Promise Pattern" and how it's used 2 37
Visual Studio installation 5 32
Wpf develop 5 29
Paging GridView 7 32
Flash (http://en.wikipedia.org/wiki/Adobe_Flash) has evolved over the years to where it has become a masterful tool for displaying content screen.  It has excellent layout placement, UI precision as well as rendering capabilities. This, along with t…
Welcome my friends to the second instalment and follow-up to our Minify and Concatenate Your Scripts and Stylesheets (http://www.experts-exchange.com/Programming/Languages/.NET/ASP.NET/A_4334-Minify-and-Concatenate-Your-Scripts-and-Stylesheets.html)…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …

762 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

6 Experts available now in Live!

Get 1:1 Help Now