Has anyone else experienced a problem databinding a dropdownlist control's SelectedValue property to a BO's Guid property when creating a new object?
I have a form that uses the FormView control to display and edit my BO. One of the properties contains the Guid id value of an item in a lookup list. I have a CslaDataSource control for both the object instance and another for the lookup list. The DropDownControl appears as:
<asp:DropDownList ID="ManufacturingPlantDropDown" runat="server" DataSourceID="ManufacturingPlantsDataSource" DataTextField="Name" DataValueField="UniqueID" SelectedValue='<%# Bind("ManufacturingPlant") %>' Width="100%"></asp:DropDownList>
This is the case in all three view templates (Edit, Item & Insert) with the exception that the Eval statement is used in the ItemTemplate.
The ManufacturingPlant property in my BO defaults to System.Guid.Empty when a new instance is created; however, there is no record in the table with this identifier so I get an exception.
What is the best way to do this for properties that are optional and/or nullable? I can't have it default to an existing value because that would require a lookup each time an object is created. And, if the property's value is optional, then I wouldn't want it to possess a legitimate value unless the user has explicitly set it.
Any suggestions?
Copyright (c) Marimer LLC