This is the script. You have a web form, and you want to offer the client to choose the year of birth.
a) hardcode the values โโin the drop down list? b) Capture valid years from the DB table
I see a service nightmare that has been copying many years of hard-coded .aspx files everywhere.
update:
for the cycle is not ideal (maintenance nightmare and error prone). Then the user must sift through 120 years that have not yet received here.
I still like the database 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
Just. No need to update the code everywhere. I feel that such data is universal, we should not hard code this schizo into a bunch of pages, which is completely contrary to reuse and error prone ... in fact, this is not practical. I would take a hit in the DB for this.
Updated (again ... thinking about it):
Here is my idea. Just create a utility or helper method GetYears that starts this loop and returns the List<int> back, and I can bind it to what I need (dropdownlist, etc.). And I like the idea of โโweb.config to support this end of the year.
source share