Solved

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

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

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Variable Event ? 3 29
VB.NET 2008 Publish Error 2 27
.NET 2008 VB and C# 6 28
VB.NET 2008 - SQL Timeout 9 25
Many of us here at EE write code. Many of us write exceptional code; just as many of us write exception-prone code. As we all should know, exceptions are a mechanism for handling errors which are typically out of our control. From database errors, t…
This article shows how to deploy dynamic backgrounds to computers depending on the aspect ratio of display
This video shows how to quickly and easily add an email signature for all users on Exchange 2016. The resulting signature is applied on a server level by Exchange Online. The email signature template has been downloaded from: www.mail-signatures…

803 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