Solved

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

Posted on 2004-10-02
1
503 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

MS Dynamics Made Instantly Simpler

Make Your Microsoft Dynamics Investment Count  & Drastically Decrease Training Time by Providing Intuitive Step-By-Step WalkThru Tutorials.

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…
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…
How to Install VMware Tools in Red Hat Enterprise Linux 6.4 (RHEL 6.4) Step-by-Step Tutorial

730 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