473,394 Members | 1,878 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

What is the best practice for DropDownList with static items?

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
Apr 7 '08 #1
1 1950
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" <bo****@company.comwrote in message
news:%2****************@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


Apr 7 '08 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Do | last post by:
Hi, How do I read through the items that are statically set in a dropdownlistbox? Usually, I have my items in a dataset before I bind to a control, so I can read the data. But if they're set...
3
by: mg | last post by:
I have a DataGrid (WebForm - C#) that has a template column that contains a dropdownlist named "DdlTest" In DataGrid1_UpdateCommand, the lin DropDownList ddlTest = (DropDownList)...
4
by: Jeff | last post by:
Help.... I have formatted a lsit of strings to add to a dropdownlist to shows three colums: id, description and price. i.e. 123 description here $12.95...
1
by: PJ | last post by:
Is it possible to prevent the drop down list from html encoding the text in ListItems? I would like to put some spaces to add padding to certain items with spaces, but when it it rendered asp.net...
4
by: Guy Noir | last post by:
Hello. Is there a pattern or best practice for the following scenario? I have a list of items I would like to compare. The number of items are decided at runtime. ObjectA, ObjectB,...
10
by: ads | last post by:
hi, after binding the dropdownlist to a datasource, ive experience this error "Cannot have multiple items selected in a dropdownlist" after using the code:...
1
by: Geoffrey van den Ouden | last post by:
I'm converting this project from ASP.NET 1.1 to 2.0, and the thing I came across is that my dropdownlist no returns the content of the Value property in a correct way. I'm not using a direct...
1
by: oldyork90 | last post by:
I have two sets of text strings. They are related to each other and are not proprietary. X group contains about 2000 short, one to three word, strings. Y contains about 50. These two groups...
1
by: shapper | last post by:
Hello, I am trying to display a DropDownList on an ASP.NET MVC view. SlidePaper.Targets contains the list of items and SlidePaper.Slide.Target contains the current value taken from the...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.