WelcomeServicesPortfolioKnowledge BaseContact Us
27 Seconds, Inc.


Knowledge base View Article

need hosting?

Need hosting? We use and love our host - CrystalTech.com!
Need hosting? We use and love our host - CrystalTech.com!

Text Disguise - CAPTCHA-image/Human Interactive Proof web services

National Holiday Dates and Bank Holiday Dates - web site that provides the dates of national and bank holidays for the United States, United Kingdom, Ireland and Scotland

Holiday Web Service - web services for programmers to provide the dates of national and bank holidays in their applications for the United States, United Kingdom, Ireland and Scotland

Our Family Heart - web site to help families communicate no matter where they are

What?! You haven't heard about the greatest remote controlled flyer to come out in years?! Checkout the FlyTech DragonFly now!

Select item from dropdownlist

Summary: A simple way to select an item from a drop-down list.
 
Keywords: DROPDOWNLIST
ITEMS
LISTBOX
SELECTED
SELECTEDINDEX
Applicable Software: Active Server Pages .NET (ASP.NET)
C#
Visual Basic .NET (VB.NET)
 
Body:

In .NET, a common task is to preselect an item in a drop-down list. Previously, in VB I would loop through the Items collection and check to see if the values matched. If so, I would then set the DropDownList's SelectedIndex property to the current loop iteration.

In .NET, the Collections class has made this MUCH easier by providing FindByValue and FindByText methods. You can now simply do:

TheDDL.SelectedIndex = TheDDL.Items.IndexOf(TheDDL.Items.FindByValue("VALUE TO FIND"))

 
Author: Douglas L. Setzer, II, http://www.27seconds.com
Posted On: 12/23/2002 6:03:50 AM

Rate this article: Average: 4.6
n/a12345678910
Comments?

Article Search   |   All Articles

 

 
©2002 27 Seconds, Inc. All Rights Reserved.