Go Back   DeveloperBarn Forums > Programming & Scripting > Code Samples

Sponsored Links

Discuss "Programmatically Select Item in ListBox or DropDownList" in the Code Samples forum.

Code Samples - Search through our code samples to give your application that something extra or provide a code sample of your own.


Reply « Previous Thread | Next Thread »  
 
LinkBack Thread Tools Display Modes
  #1  
Old June 27th, 2008, 10:05 AM
jmurrayhead's Avatar
The Barnfather

 
Join Date: Mar 2008
Location: Reston, VA, USA
Posts: 820
Thanks: 20
Thanked 74 Times in 71 Posts
Blog Entries: 5
Rep Power: 3
jmurrayhead has a spectacular aura aboutjmurrayhead has a spectacular aura aboutjmurrayhead has a spectacular aura about

Awards Showcase
Microsoft SQL Server Microsoft Windows Microsoft .Net Classic ASP 
Total Awards: 4

Default Programmatically Select Item in ListBox or DropDownList

A common question that I see posted all over the place is "How can I programmatically select an item in my dropdownlist or listbox based off a certain value?"

It's actually quite simple and here's how to do it:

Code:
For Each Item As ListItem In MyListBox.Items
    If Item.Value = "4" Then
        Item.Selected = True
    End If
Next
This is useful when, for example, you're reading values from a DataReader and what to pre-select an option based off of that value.
__________________
jmurrayhead
If you agree with me... click the icon!
If my post solved your problem, click the button in the lower right-hand corner of the post.

Join our Folding team: DeveloperBarn Folding
Reply With Quote
Sponsored Links
Reply

  DeveloperBarn Forums > Programming & Scripting > Code Samples

Bookmarks

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Select Top 100 Percent Wolffy SQL Development 1 July 17th, 2008 03:46 PM
How do you add a static item to a dynamic dropdownlist Shem .Net Development 19 July 4th, 2008 08:14 AM
Select latest dates Wolffy SQL Development 2 April 11th, 2008 09:25 AM
sQL select add '%' next to value peebman2000 SQL Development 8 March 28th, 2008 10:21 AM
[ASP.Net/VB.Net] Programmatically Add Item to Validation Summary jmurrayhead Code Samples 0 March 20th, 2008 09:41 AM


All times are GMT -4. The time now is 07:31 PM.



Content Relevant URLs by vBSEO 3.2.0