Solved

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

Posted on 2004-10-02
1
506 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
[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
1 Comment
 
LVL 7

Accepted Solution

by:
jackiechen858 earned 250 total points
ID: 12211248

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

Instantly Create Instructional Tutorials

Contextual Guidance at the moment of need helps your employees adopt to new software or processes instantly. Boost knowledge retention and employee engagement step-by-step with one easy solution.

Question has a verified solution.

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

In my previous article (http://www.experts-exchange.com/Programming/Languages/.NET/.NET_Framework_3.x/A_4362-Serialization-in-NET-1.html) we saw the basics of serialization and how types/objects can be serialized to Binary format. In this blog we wi…
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…
Michael from AdRem Software explains how to view the most utilized and worst performing nodes in your network, by accessing the Top Charts view in NetCrunch network monitor (https://www.adremsoft.com/). Top Charts is a view in which you can set seve…
If you’ve ever visited a web page and noticed a cool font that you really liked the look of, but couldn’t figure out which font it was so that you could use it for your own work, then this video is for you! In this Micro Tutorial, you'll learn yo…

726 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