obb-taurus
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
Thanks
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
Hopefully that helps.
Thanks
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
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.