I have been given the task of creating a custom server control to be added to our ASP.NET applications template. I'm looking to create a custom server control that inherits from System.Web.UI.WebControls.DropDownList to handle the following issue:
ISSUE: There are several code lookup tables in our databases that have three columns: Code, Description, and Enabled. The enabled column is to be set to 'N' for Not Enabled when the option should no longer be an available option for the user. We cannot delete the record due to referential integrity constraints. We cannot simply return only records from the lookup tables that are marked 'Y' for Enabled because if someone retrieves a previously created record with an option that is now marked 'N', the "Specified argument was out of the range of valid values" exception will occur.
I am looking for an effecient way to display only enabled options plus the option that the record was saved with if it is not in the list. I am thinking about returning all records from the lookup tables and storing them in ViewState or Cache and then internally removing all items from the list that have the Enabled column marked as 'N'. When SelectedValue is set, if the option is not in the Items collection, it will be retrieved from the recordset in ViewState or Cache and programmatically added.
My second idea is to have a read-only textbox overlaying a dropdown (with exception of the dropdown arrow) and to always return the "Code" and "Description" from the main stored procedure. The textbox will have the text and a custom "Value" property that is set when the dropdown option is selected. Upon saving the record, the value is always read from the textbox's custom value property.
I'd prefer a custom DropDownList without a textbox but do not know if it's possible. Any ideas anyone?
NOTE: We are still unfortunately on .NET Framework 1.1