Link to home
Start Free TrialLog in
Avatar of obb-taurus
obb-taurusFlag for Canada

asked on

Should fields be created in classes to hold ID values from list boxes or drop downs?

I would like to get a sense of what the best way is to deal with ID values of drop down lists, list boxes etc.   Should a field be created in the respective class to hold the ID value or would it be better to just pass it through as a parameter to the method that is handling the database interaction or is there an even better way that what I'm suggesting?

Thanks
Avatar of Dmitry G
Dmitry G
Flag of New Zealand image

I'm not quite sure what are you talking about. Probably you need to clarify your question.

What do you display in this controls? If I display, say, Company, Region etc, i.e. some objects that correspond to database records, I believe these objects should encapsulate this "id information" as a field. And normally this is a read-only field as IDs are set by a DB engine.

Also, business object like 'Company', 'Order', 'StockLine' often have methods like save, e.g.:
 
               Order.save();

Such a method requires all the information for this order stored in business object itself and not passed from somewhere. Normally, if you want to change a field value, you do something like:

           myCompany.Name = "Pokemon Ltd.";

and then save the object to a DB as shown above.
Avatar of obb-taurus

ASKER

Sorry, I was a little rushed when posting the question.  I think you got the gist of my question, if for example the drop down list is populated from a lookup table in the database that contains States and I have a Customer class which needs State information, should I have a field in the Customer class that will contain the ID value retrieved from the drop down (eg. dropdown.SelectedValue) or is there a better way to handle this situation.

Hopefully that helps.

Thanks
ASKER CERTIFIED SOLUTION
Avatar of Dmitry G
Dmitry G
Flag of New Zealand image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial