473,387 Members | 1,603 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,387 software developers and data experts.

Best practice for binding the 50 states to a combo box

I have a few options regarding populating the state combo box

1. On page load, get the 50 states from the database
2. On application start, get the 50 states from the database and cache them
in application cache. On page load, get the states from application cache
3. Create a class in App Code folder, declare a public string array
property, hard code the 50 states. On page load, call this property to get
the 50 states
4. Create a states user control which contain a combo box, with 50 states
hard coded in design time

Please share with me how you usually bind your states combo box. Your
thoughts and recommendations are greatly appreciated.
Jun 30 '06 #1
6 1325
Hi Ethan,

Number 1 and 2 are too expensive. The state names never (at least almost)
change.

Between number 3 and 4, I prefer number 4 as the least expensive in terms of
resources, although I'd probably go with a custom Server Control (for easy
reusability between projects).

--
HTH,

Kevin Spencer
Microsoft MVP
Professional Chicken Salad Alchemist

Big thicks are made up of lots of little thins.
"Ethan V" <aa*@aaa.aaa> wrote in message
news:OK**************@TK2MSFTNGP05.phx.gbl...
I have a few options regarding populating the state combo box

1. On page load, get the 50 states from the database
2. On application start, get the 50 states from the database and cache
them in application cache. On page load, get the states from application
cache
3. Create a class in App Code folder, declare a public string array
property, hard code the 50 states. On page load, call this property to get
the 50 states
4. Create a states user control which contain a combo box, with 50 states
hard coded in design time

Please share with me how you usually bind your states combo box. Your
thoughts and recommendations are greatly appreciated.

Jun 30 '06 #2
If your "state" example is specifically a state example, then I'd probably
put them into a strongly typed dataset, and have the .xml to populate the
dataset handy.

Thinking outside of the State example. where you have a look up table...
that ~maybe changes every blue moon (in the db), then I usually do this:
1. Check the Application (or Session) for an existing copy.
2. If it doesn't exist, then read a fresh set out of the db, and put them
into the Application or Session object.
3. Return the Appliacation (or Session) copy.

I usually throw a "bool forceRefresh" parameter on it also. For that seldom
case that I make a change.
(Like, lets say I add a new state to the database. I'd call the function
with a "true" to make sure I refreshed the Application (or Session) data.

public ICollection RetrieveGoodEnoughStates( bool forceRefresh )

{

string keyname = "STATES";

ArrayList states;
bool readValuesFresh = false;

if (forceRefresh)
{

readValuesFresh = true;
}
else
{
if (null!=Session[keyname])
states = Session[keyname] as ArrayList;
}
else
{
readValuesFresh = true;
}

if (readValueFresh || null==states)
{
states = GetTheStatesFromDatabaseSomehow();
Session[keyname] = states;
}

return states;
}

Soemthing like that. YOu can clean it up, but you get the idea.

Check my blog:
http://sholliday.spaces.msn.com/ 10/24/2005 entry

for a object wrapper. Using this, I never use Session["keyname"], I use the
somewhat nicer wrapped object.

You could easily convert this to an ApplicationDataStore
"Ethan V" <aa*@aaa.aaa> wrote in message
news:OK**************@TK2MSFTNGP05.phx.gbl...
I have a few options regarding populating the state combo box

1. On page load, get the 50 states from the database
2. On application start, get the 50 states from the database and cache them in application cache. On page load, get the states from application cache
3. Create a class in App Code folder, declare a public string array
property, hard code the 50 states. On page load, call this property to get
the 50 states
4. Create a states user control which contain a combo box, with 50 states
hard coded in design time

Please share with me how you usually bind your states combo box. Your
thoughts and recommendations are greatly appreciated.

Jun 30 '06 #3
On Fri, 30 Jun 2006 11:05:26 -0400, "Kevin Spencer" <uc*@ftc.gov>
wrote:
Hi Ethan,

Number 1 and 2 are too expensive. The state names never (at least almost)
change.

Between number 3 and 4, I prefer number 4 as the least expensive in terms of
resources, although I'd probably go with a custom Server Control (for easy
reusability between projects).


Hi Kevin,

I'm curious if you are confident that creating a string array in code
is more efficient than cache. Both take up the same amount of server
memory I think and with Cache, there is no object type allocation on
each request. I've always used Cache for this type of thing, but am
willing to change if it's not the right way to go.

Peter Kellner
http://peterkellner.net
Jun 30 '06 #4
making decisions should be based on code reuse. look at these scenarios:

1) these is only one dropdown the app and its for states. no need to do more
then hard code the list
2) the only dropdown in the app is state, and its on several pages. well
this kinda begs for a state dropdown control
3) you have lots of dropdowns and they get reused. this begs for a common
data repository with common load routines. here performance issues may lead
to a common cache.

-- bruce (sqlwork.com)

"Ethan V" <aa*@aaa.aaa> wrote in message
news:OK**************@TK2MSFTNGP05.phx.gbl...
I have a few options regarding populating the state combo box

1. On page load, get the 50 states from the database
2. On application start, get the 50 states from the database and cache
them in application cache. On page load, get the states from application
cache
3. Create a class in App Code folder, declare a public string array
property, hard code the 50 states. On page load, call this property to get
the 50 states
4. Create a states user control which contain a combo box, with 50 states
hard coded in design time

Please share with me how you usually bind your states combo box. Your
thoughts and recommendations are greatly appreciated.

Jun 30 '06 #5
What about internationalization issues?

What if your boss wants a Spanish version next year?
What if your boss wants Canadians (now with Provinces!) to use your app
next year?

1. think about resources
2. use the cache and buy more cheap ram :)
3. separate data from presentation
4. code for clarity first, then performance if it's an issue

bruce barker (sqlwork.com) wrote:
making decisions should be based on code reuse. look at these scenarios:

1) these is only one dropdown the app and its for states. no need to do more
then hard code the list
2) the only dropdown in the app is state, and its on several pages. well
this kinda begs for a state dropdown control
3) you have lots of dropdowns and they get reused. this begs for a common
data repository with common load routines. here performance issues may lead
to a common cache.

-- bruce (sqlwork.com)

"Ethan V" <aa*@aaa.aaa> wrote in message
news:OK**************@TK2MSFTNGP05.phx.gbl...
I have a few options regarding populating the state combo box

1. On page load, get the 50 states from the database
2. On application start, get the 50 states from the database and cache
them in application cache. On page load, get the states from application
cache
3. Create a class in App Code folder, declare a public string array
property, hard code the 50 states. On page load, call this property to get
the 50 states
4. Create a states user control which contain a combo box, with 50 states
hard coded in design time

Please share with me how you usually bind your states combo box. Your
thoughts and recommendations are greatly appreciated.


Jun 30 '06 #6
Thank you so much everyone for your inputs. I am amazed at the responses I
got because your suggestions not only help me solve this particular
implementation, but they also touch on best practices philosohpy. Thanks so
much again everyone.

"Ethan V" <aa*@aaa.aaa> wrote in message
news:OK**************@TK2MSFTNGP05.phx.gbl...
I have a few options regarding populating the state combo box

1. On page load, get the 50 states from the database
2. On application start, get the 50 states from the database and cache
them in application cache. On page load, get the states from application
cache
3. Create a class in App Code folder, declare a public string array
property, hard code the 50 states. On page load, call this property to get
the 50 states
4. Create a states user control which contain a combo box, with 50 states
hard coded in design time

Please share with me how you usually bind your states combo box. Your
thoughts and recommendations are greatly appreciated.

Jul 1 '06 #7

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

Similar topics

16
by: D Witherspoon | last post by:
I am developing a Windows Forms application in VB.NET that will use .NET remoting to access the data tier classes. A very simple way I have come up with is by creating typed (.xsd) datasets. For...
0
by: Neo | last post by:
I was wondering what is the "right" way to deal with datasets is. Particularly sharing DataSets between forms. Here is my situation. I have a simple Customer Database, that holds some information...
136
by: Matt Kruse | last post by:
http://www.JavascriptToolbox.com/bestpractices/ I started writing this up as a guide for some people who were looking for general tips on how to do things the 'right way' with Javascript. Their...
17
by: | last post by:
I have an app that retrieves data from an Access database. At the moment I have the SQL string as a Const in my app. I understand this is not best practice. I don't want the user to have access to...
2
by: SoftWhiteDelgiht | last post by:
Help me. I am obviously stupid! :-) I am just starting out with VB.Net and am trying to do a simple master/detail form with a SqlServer backend. I have created a combo box which is to populate with...
0
by: JSantora | last post by:
Essentially, InsertAT is broken! For the past couple of hours, I've been getting this "Parameter name: '-2147483550' is not a valid value for 'index'." error. Apparently, its caused by having...
10
by: Ren | last post by:
Hi All, I'm still rather new at vb.net and would like to know the proper way to access private varibables in a class. Do I access the variable directly or do I use the public property? ...
3
by: cbrown | last post by:
I am rebuilding an existing application that relies on an SQL DB. The app is a scheduling/employee management program. My question pertains to best practices in dotnet and database. I use a 3...
3
by: Max | last post by:
Hello, I made a windows form with a combo box and 4 text boxes. All 5 objects should get their data from a data set which is populated in the form load method. The combo box has item ids. When...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
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
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
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

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.