StrataFrame Forum

WebForms - BO.Add method causes error with DropDownList

http://forum.strataframe.net/Topic17666.aspx

By Jiri Brazda - 7/7/2008

Hi,

I'm using WebForms with DropDownList (actually I have two DropDownLists - one has PopulationType set to Enumerator and second BusinessObject). Everything works fine - navigation througs records, editing, saving, deleting - all works fine. All except adding new row. When I click on the Add button and call BO.Add method, the error below my post occurs. When I remove these two dropdowns and there only remains textboxes, checkboxes etc. - the BO.Add method doesn't produce any error and I can add new records without problems.

Finally - I have found a workaround that I can use in some of forms but not all:

I use one form for searching and navigation through records and one for editing. The editing form doesn't allow any navigation. On Page_Load event of the editing form I check whether I should read record from DB by primary key or add new record - and in this moment I call BO.Add method and it works fine with DropDowns.

However, I need to use searching, navigation and editing in single form.

Any solution, please?

Thanks

Here is the error message:

 

Server Error in '/' Application.

 

'ddBPaID' 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: 'ddBPaID' 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: 'ddBPaID' has a SelectedValue which is invalid because it does not exist in the list of items.Parameter name: value]   System.Web.UI.WebControls.ListControl.set_SelectedValue(String value) +1827674[TargetInvocationException: Exception has been thrown by the target of an invocation.]   System.RuntimeMethodHandle._InvokeMethodFast(Object target, Object[] arguments, SignatureStruct& sig, MethodAttributes methodAttributes, RuntimeTypeHandle typeOwner) +0   System.RuntimeMethodHandle.InvokeMethodFast(Object target, Object[] arguments, Signature sig, MethodAttributes methodAttributes, RuntimeTypeHandle typeOwner) +72   System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture, Boolean skipVisibilityChecks) +371   System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture) +29   System.Reflection.RuntimePropertyInfo.SetValue(Object obj, Object value, BindingFlags invokeAttr, Binder binder, Object[] index, CultureInfo culture) +96   System.Reflection.RuntimePropertyInfo.SetValue(Object obj, Object value, Object[] index) +24   MicroFour.StrataFrame.Business.TypePropertyCache.SetPropertyValue(Type OwnerType, Object Owner, String PropertyName, Object Value, String FormatString) +260   MicroFour.StrataFrame.Business.TypePropertyCache.SetPropertyValue(Object Owner, String PropertyName, Object Value) +82   MicroFour.StrataFrame.Business.BusinessLayer.PushDataToWebControl(IWebBusinessBindable ControlToBind, IWebBinding Binding) +273   MicroFour.StrataFrame.Business.BusinessLayer.BindDataToWebControl(IWebBusinessBindable ControlToBind, IWebBinding Binding) +1024   MicroFour.StrataFrame.Business.BusinessLayer.BindDataToWebControlPrimary(IWebBusinessBindable ControlToBind) +46   MicroFour.StrataFrame.UI.Web.BasePage.BindControls() +224[UIException: An error occurred while binding data to the web control 'ddBPaID'.]   MicroFour.StrataFrame.UI.Web.BasePage.BindControls() +577   MicroFour.StrataFrame.UI.Web.BasePage.Page_PreRender(Object sender, EventArgs e) +30   System.Web.UI.Control.OnPreRender(EventArgs e) +2117836   System.Web.UI.Control.PreRenderRecursiveInternal() +86   System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +2041

 


Version Information: Microsoft .NET Framework Version:2.0.50727.1434; ASP.NET Version:2.0.50727.1434

By Trent L. Taylor - 7/7/2008

The problem is that the web combos are somewhat unforgiving if a value doesn't exist within the list that it is expecting.  One way to get around this is to add a top most item of the initialized value.  For example, when a new record is created it initializes the values (i.e. an integer as a 0, etc.).  But there is not a 0 in the list.  You can have a rule that ensures that a value is selected.  But the way we get around this is to create an item in the combo that has a "<Select Item>" row so that you will never get this error.  The selected value would be the initialized value so it would properly "line-up" when bound.
By Jiri Brazda - 7/7/2008

Hi Trent,

thank You for Your answer. It sounds like a solution, however I do not know how to make a workaround with "<Select Item>". Would You be so kind and post here a piece of code, please?

The second point is what I would like to ask too - when I would like to have the possibility to NOT select the value from combo: It seems it is not possible to set this property on combo but I have to add a new datarow with NULL or zero value to datatable that is returned by function I use for combo population. And when I would like to have this field empty, the added row will be selected - is it right? Or is there any more sophisticated way?

Thank You

By Trent L. Taylor - 7/8/2008

It depends on how you are populating the combo boxes.  Are you just creating a DataTable and then attaching that as a data source or what?
By Jiri Brazda - 7/8/2008

I'm using it the same way as in wonforms - the following properties are set:

- BindingField: BPaID

- BindingObjectName: AppUser

- PopulationDataSourceSettings: B4UWebDB.M51.cBusinessPartner|FillForSelect;|BPaName,|{0}|BPaID

- PopulationType: BusinessObject

All other properties are left default...

By Trent L. Taylor - 7/10/2008

Jiri,

I missed this post, sorry Blush

It works just like the WinForms combos.  You can just set the TopMostItem property with the description and value.  You will see it in the property sheet:

By Jiri Brazda - 7/10/2008

Trent,

thank You, this solution is really easy and it works perfectly.

Thank You againg!!!

By Trent L. Taylor - 7/10/2008

Glad it got you what you needed...and sorry you had to wait so long for your answer!