my detailsview is going to the default value when insert event is cancelled

navagomeza

Member
Joined
Jan 13, 2014
Messages
12
Programming Experience
1-3
my details view is linked to the selected value of a drop down list. it all works fine, but when the details view enters insert mode, one of the things that happen in the code behind is clearing the drop down values.

If
dvRecipeItem.CurrentMode = DetailsViewMode.Insert Then
ddRecipeItemNumber.Items.Clear()
End If

but if the insert event gets cancelled, then this happens to the drop down

If
dvRecipeItem.CurrentMode = DetailsViewMode.ReadOnly Then
ddRecipeItemNumber.DataBind()
End If

then the drop down goes back to contain all the values from datasource. but what happens to the details view is that instead that picking up the value from the drop down list, it goes to the default value = 1 that is specified in the entity datasource, and if I remove that default value, and then try to insert a new item, and cancel before saving it, then the details view disappears although the dropdownlist does contain a value. seems like it is not binding back.

<asp:EntityDataSource
ID="EntityDataSource_RecipeItemDetail"
runat="server"
ConnectionString="name=OLTPEntities"
DefaultContainerName="OLTPEntities"
EnableFlattening="False"
EntitySetName="RefineRecipe"
Where="it.Id = @RecipeId"
EnableDelete="True"
EnableInsert="True"
EnableUpdate="True"
EntityTypeFilter="RefineRecipe">
<WhereParameters>
<asp:ControlParameter
ControlID="ddRecipeItemNumber"
DbType="Int32"
DefaultValue="1"
Name="RecipeId"
PropertyName="SelectedValue" />
</WhereParameters>
</asp:EntityDataSource>

I would like to ask for help in order to figure out how to assign the drop down value to the details view on this event insert/ cancel
Any help would be nice, really.
Thank you very much.
 
Back
Top