BLEIP
asked on
Custom Extended ASP.NET DropDownList
Hello:
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. DropDownLi st 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
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.
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
ASKER
We use stored procedures to retrieve LOVs (List Of Values) that are then added to the application's Cache. The Cached objects are then retrieved, cast back to a datatable, and bound to the DropDownLists during the inital page load event. When a form is opened in Add mode, there will not be a record available for the 'OR' portion of your SQL statement. I suppose I could loop through all DropDownList DataSource tables each time a record is loaded to verify whether the required options are in the collection and if not add them but I was trying to avoid rebinding all DropDownLists every time a new record is selected. I'm looking for the most efficient way.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
nbove: Thanks for your responses. I ended up modifying the stored procs to return all records in each code lookup table (enabled and disabled). I then have a function that accepts a stored proc name, cache key name, and selectedValue string. The function executes the stored proc and stores the datatable in Cache and then creates a dataview on the datatable with a filter that retrieves all records that are enabled or match the optional selectedValue parameter. The only difference now is instead of executing the function that gets the datasource and binds it to the dropdownlist once in the initial page_load event, I am calling it each time the record is retrieved or the form is cleared as the result of being put in ADD mode or a record being deleted. Thanks for your help.
Open in new window
Then simply pass in as a parameter the ID that the record is currently set to. This will retrieve all enabled domain values, plus the currently selected domain value.