views:

17

answers:

0

One common scenario we run into is with a drop down being databound inside the edit template of a ListView. This usually works pretty well, but I cannot figure out a good way to handle exceptions, for example, look at this error from our website:

Server Error in '/' Application.

'ddlLender' has a SelectedValue which is invalid because it does not exist in the list of items. Parameter name: value Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.ArgumentOutOfRangeException: 'ddlLender' has a SelectedValue which is invalid because it does not exist in the list of items. Parameter name: value

Source Error:

An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.

Stack Trace:

[ArgumentOutOfRangeException: 'ddlLender' has a SelectedValue which is invalid because it does not exist in the list of items. Parameter name: value] System.Web.UI.WebControls.ListControl.PerformDataBinding(IEnumerable dataSource) +1604654 System.Web.UI.WebControls.ListControl.OnDataBinding(EventArgs e) +107 System.Web.UI.WebControls.ListControl.PerformSelect() +34 System.Web.UI.WebControls.BaseDataBoundControl.DataBind() +73 System.Web.UI.Control.DataBindChildren() +211 System.Web.UI.Control.DataBind(Boolean raiseOnDataBinding) +102 System.Web.UI.Control.DataBind() +15 System.Web.UI.WebControls.ListView.CreateItemsWithoutGroups(ListViewPagedDataSource dataSource, Boolean dataBinding, InsertItemPosition insertPosition, ArrayList keyArray) +681 System.Web.UI.WebControls.ListView.CreateChildControls(IEnumerable dataSource, Boolean dataBinding) +776 System.Web.UI.WebControls.ListView.PerformDataBinding(IEnumerable data) +33 System.Web.UI.WebControls.DataBoundControl.OnDataSourceViewSelectCallback(IEnumerable data) +114 System.Web.UI.DataSourceView.Select(DataSourceSelectArguments arguments, DataSourceViewSelectCallback callback) +31 System.Web.UI.WebControls.DataBoundControl.PerformSelect() +142 System.Web.UI.WebControls.ListView.PerformSelect() +57 System.Web.UI.WebControls.BaseDataBoundControl.DataBind() +73 System.Web.UI.WebControls.BaseDataBoundControl.EnsureDataBound() +82 System.Web.UI.WebControls.BaseDataBoundControl.OnPreRender(EventArgs e) +22 System.Web.UI.Control.PreRenderRecursiveInternal() +80 System.Web.UI.Control.PreRenderRecursiveInternal() +171 System.Web.UI.Control.PreRenderRecursiveInternal() +171 System.Web.UI.Control.PreRenderRecursiveInternal() +171 System.Web.UI.Control.PreRenderRecursiveInternal() +171 System.Web.UI.Control.PreRenderRecursiveInternal() +171 System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +842


Version Information: Microsoft .NET Framework Version:2.0.50727.3603; ASP.NET Version:2.0.50727.3614

In this example, a value from our database is not valid as far as the list of items in the drop down. 99% of the time, the value is valid, and the page works fine.

I know there are other solutions (not using these controls together this way, disallowing invalid values in the database, etc) but I can't believe Microsoft wouldn't give us a good way to handle this exception.