[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

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

Posted on 2004-10-02
1
Medium Priority
?
513 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 1000 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

Get your Conversational Ransomware Defense e‑book

This e-book gives you an insight into the ransomware threat and reviews the fundamentals of top-notch ransomware preparedness and recovery. To help you protect yourself and your organization. The initial infection may be inevitable, so the best protection is to be fully prepared.

Question has a verified solution.

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

For those of you who don't follow the news, or just happen to live under rocks, Microsoft Research released a beta SDK (http://www.microsoft.com/en-us/download/details.aspx?id=27876) for the Xbox 360 Kinect. If you don't know what a Kinect is (http:…
Today I had a very interesting conundrum that had to get solved quickly. Needless to say, it wasn't resolved quickly because when we needed it we were very rushed, but as soon as the conference call was over and I took a step back I saw the correct …
In this video, Percona Solutions Engineer Barrett Chambers discusses some of the basic syntax differences between MySQL and MongoDB. To learn more check out our webinar on MongoDB administration for MySQL DBA: https://www.percona.com/resources/we…
This lesson discusses how to use a Mainform + Subforms in Microsoft Access to find and enter data for payments on orders. The sample data comes from a custom shop that builds and sells movable storage structures that are delivered to your property. …

656 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