Reputation: 471
I have a details view bound to an entity data source and am trying to use it to update some things. But the ItemUpdating event never fires when I press the Update button.
Here is the code:
<asp:DetailsView ID="DetailsView1" DataKeyNames="Id" runat="server" AutoGenerateRows="False" OnDataBound="DetailsView_DataBound"
DataSourceID="eds2" BorderWidth="0" OnModeChanging="OnModeChanging" AutoGenerateEditButton="true" OnItemUpdated="DetailsView_OnItemUpdated" OnItemUpdating="DetailsView_OnItemUpdating"
EmptyDataText="N/A"
CellPadding="0" CellSpacing="7" GridLines="None" CssClass="Center">
<Fields>
<asp:BoundField DataField="Name" HeaderText="Name: " />
<asp:BoundField DataField="AccessCode" HeaderText="Access Code: " />
<asp:BoundField DataField="Password" HeaderText="Password: " />
<asp:BoundField DataField="MaxVoters" HeaderText="Max Voters: " />
<asp:BoundField DataField="Created" HeaderText="Created: " ReadOnly="true" />
<asp:BoundField DataField="Updated" HeaderText="Updated: " ReadOnly="true" />
</Fields>
</asp:DetailsView>
And the EntityDataSource:
<asp:EntityDataSource ID="eds2" runat="server" ConnectionString="name=BallotOnlineEntities"
DefaultContainerName="EntitiesOne" EntitySetName="Accounts" OnInserting="eds1_Inserting" OnUpdating="eds1_Updating" OnDeleting="eds1_Deleting"
EnableDelete="True" EnableFlattening="False" EnableInsert="True"
EnableUpdate="True">
<UpdateParameters>
<asp:Parameter Name="AccessCode" Type="String" />
</UpdateParameters>
</asp:EntityDataSource>
During the OnModeChange I set the where property of the Datasource so it queries for the right item, this was the only way I could get it to work, but I dont think that is a problem.
protected void OnModeChanging(object sender, DetailsViewModeEventArgs e)
{
eds2.Where = string.Format("it.AccessCode = '{0}'",accountIDPlaceholder.Text );
DetailsView1.DataBind();
}
protected void DetailsView_OnItemUpdating(object sender, DetailsViewUpdateEventArgs e)
{
//Do Stuff
}
Any ideas why my event is not firing? The reason I want it to fire is that it does not seem to update the entities at all when I click update.
Thanks,
Ty Rozak
Upvotes: 2
Views: 1265
Reputation: 1528
Make sure that EnableViewState
on the page is not set to false.
Upvotes: 0