E:\web\learnaspcom\htdocs\freebook\learn\ubtoc.xml LearnAsp.com - ASP ASP.net Free Lessons
Search Search

#1 worldwide
FREE Coding Lessons

since 1996
   THE BEST WAY to learn ASP & Asp.net!
Advertise Here!
click for details
Credits Host:
DiscountASP.net
Server Admin:
The "Team"
Contact Info.
Charles M. Carroll
<Asp.net blog>
<personal site>
xxx

DropDownList, ListBox Core Methods
by Charles Carroll

DropDown Lists and Listboxes are easy to fill but unless one learns a few of the core methods they can be frustrating.

  • Add An Item To End:

dropWhatever.Items.Insert(0, New ListItem(" --please choose state--", -1))

  • Select an Item In Multi-select List:

dropWhatever.Items.FindByValue("MD").Selected=true

  • Find The Value via the corresponding text

drpP1.SelectedIndex = drpP1.Items.IndexOf(drpP1.Items.FindByValue("MD"))

  • Act only on Selected Items

dim listitem1 as listItem
For Each listItem1 In listboxWhatever.Items
    If oItem.Selected = true then
       ' do something with selected items
    END IF
NEXT

System.Web.UI.WebControls.ListItem is fully qualified name.

There are many worthy charities!!. But perhaps help starving children in Africa or South America AND help Charles too. a $5 tip buys him lunch at McDonalds, a $20 tip buys his kid Hitoshi a new computer game, a $39 tip buys his daughter Michiko a few nice outfits. See our donor list.