What is the best practice for DropDownList with static items?

B

bogdan

Hi,

I'd like to use a dropdownlist in a formview to map numeric values to
'user-friendly' descriptions. The dropdownlist items' values need to be
bound to a column in a db table. For example, users might see "Type1",
"Type2", and "Type3" but corresponding values stored in db are 1, 2, and 3.
Seems like a very common scenario. Could anyone please let me know what the
best practice is in this case? Should I create a custom data source or
simply bind an array to the dropdownlist in Page_Load()? I remember seeing
a sample that I liked (might've been one of Scott Mitchell's tutorials) some
time ago but can't find it now.

I'm quite comfortable with binding db data sources to controls.

Thanks,
Bogdan
 
D

David Wier

the very simplest of solutions would be to create a simple stored procedure,
retrieving the items, putting the 1, 2 & 3 items as the DataValueField item
of the Dropdownlist, and the Type2 items as the DataTextField (visible)

You could either create a Dataset (xsd), and ObjectDataSource for this, or
simply create a SQLDataSource for it

David Wier
http://aspnet101.com
http://iWritePro.com - One click PDF, convert .doc/.rtf/.txt to HTML with no
bloated markup
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Staff online

Members online

Forum statistics

Threads
473,995
Messages
2,570,230
Members
46,816
Latest member
SapanaCarpetStudio

Latest Threads

Top