What is the best practice for DropDownList with static items?

What is the best practice for DropDownList with static items?

am 07.04.2008 18:17:15 von 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

Re: What is the best practice for DropDownList with static items?

am 07.04.2008 18:44:39 von 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


"bogdan" wrote in message
news:%23hsvfrMmIHA.5268@TK2MSFTNGP05.phx.gbl...
> 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
>
>