Our projects user a lot dropdownlist control. My question is what should we store in the database for them, the order number or text itself.
For example:
<option value="1">This is the first option</option>
<option value="2">This is the second option</option>
Convert the “1” and “2” to smallint 1, 2 to the database.
–OR–
<option value="This is the first option">This is the first option</option>
<option value="This is the second option">This is the second option</option>
use varchar data type in the field.
order number is good for the statistics, but Text is dynamic for modification, for example insert another option between 1 and 2 and do not have to worry about the order. Also if it is embedded in the GridView, we can simply pull the text rather than put an DropDownList control in the GridView in order to see the text.
If you don’t want to load the drop down lists from database tables then here is what I would do. Use the integer values in the drop down lists. Then what you’re going to want to do is create tables in the database that mimic those values because that will give you the ability to build foreign keys on the tables and perform reporting that makes sense as well as statistics (like you talked about).
Finally, you may want to create
Enum‘s that match the values because that will make them easier to work with internally in the program. For example:Now, what I just described is only one step from not having to maintain the drop downs because you just need to load them from the database instead, which you can find a good example of that here.