When a user accesses a page that is populating a form for edit using existing data, i have to programmatically select a DDL with the data from the DB. But I dont want to put try catch blocks around every flamin' line that does this just in case the database is holding a value that doesn't exist in the DDL items collection.
Say, for example, that i have a DDL with items "apple", "orange", and "tangerine". The database holds the value "apple" but i later take that value out of the dropdownlist entries. When the code tries to select the item for "apple" and can't find it, it crashes. Isn't there a way to do something like the attached code?
Note: I know about ddl.items.contains(), but it makes you pass in an object of type ListItem and frankly, i don't want to be concerned with both text and value pairs. I just want to check if the value exists before I run the selection code.
Any ideas?
Say, for example, that i have a DDL with items "apple", "orange", and "tangerine". The database holds the value "apple" but i later take that value out of the dropdownlist entries. When the code tries to select the item for "apple" and can't find it, it crashes. Isn't there a way to do something like the attached code?
Note: I know about ddl.items.contains(), but it makes you pass in an object of type ListItem and frankly, i don't want to be concerned with both text and value pairs. I just want to check if the value exists before I run the selection code.
Any ideas?