Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Defualt Value on a Drop Down Box 2

Status
Not open for further replies.

1Data

MIS
Joined
Sep 30, 2005
Messages
66
Location
US
I know this is kinda of a dumb question because it's probably a property somewhere but how can I set my default value on a drop down box that is being populated by a database table. I apologize for my ignorance in advance...
 
If the list is a collection you add manually (not databound), you can set the selected property of that item in the collections dialog
If the list is databound you can do a couple of things
Code:
  dropdownlist.Items(<index>).Selected = TRUE
OR
  dropdownlist.SelectedValue = "Some Value"
OR
  dropdownlist.SelectedIndex = x
 
And one other way just for the hell of it:
Code:
DDL.Items.FindByValue("Item1").Selected = True
If you want to read up on the DropDownList, the following article may help:



____________________________________________________________

Need help finding an answer?

Try the Search Facility or read FAQ222-2244 on how to get better results.
 
Thanks for that jbenson001 but I have a follow up question. I tried putting my default value before the Databind() and it get pushed out ofcourse. That is pretty predictable, however after I put it after the Databind() it puts it last on my Drop Down List is there a way around this problem. I was think maybe some sorting?
 
You can simply add it to your datatable (if that is what you have your data in) before you call the DataBind method and use Rows.InsertAt to insert it into the first row.


____________________________________________________________

Need help finding an answer?

Try the Search Facility or read FAQ222-2244 on how to get better results.

 
Ca8M - Thanks that article answered my second questio thank you guys...great posts.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top