Hard Code List of Years?
asp.net, c#
Solution
C) Use a for-loop to generate the years in a range of your choice.
Something as simple as this pseudocode:
for (int i = 1900 ; i < THIS_YEAR - 13 ; i++)
{
validyears.options.Add(i);
}
Problem
This is the scenario. You've got a web form and you want to prompt the customer to select their birth year. a) hard code the values in the dropdown list? b) Grab valid years from a DB table I can see a maintenance nightmare with copying a set of years hard coded in .aspx files everywhere. updated: for loop is not ideal (maintenance nightmare and error prone). The user then has to sift through 120 years that haven't even got here yet. I still like the DB approach: ``` * Single point of data * No duplication of code * Update the table as needed to add more years * Year table values could be used for some other dropdown for some other purpose entirely for something other than Birth year ``` Simple as that. No need to go updating code everywhere. I feel for data that is universal like this, we shouldn't be hard coding this shiza into a bunch of pages which is totally going against reuse and error prone...really it's not pratical. I'd take the hit to the DB for this. Updated (again...after thinking about this): Here's my idea. Just create a utility or helper method called GetYears that runs that loop and returns a `List<int>` back and I can bind that to whatever I want (dropdownlist, etc.). And I like the web.config idea of maintaining that end year.