1
我有一個綁定到實體數據源的細節視圖,並試圖用它來更新一些東西。但是當按下更新按鈕時,ItemUpdating事件從不會觸發。ItemUpdating不使用EntityDataSource調用DetailsView
下面是代碼:
<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>
而且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>
在我設定的OnModeChange的,其中數據源,以便將查詢權項目的性質,這是唯一的我可以得到它的工作方式,但我不認爲這是一個問題。
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
}
任何想法,爲什麼我的活動沒有解僱?我希望它觸發的原因是,當我點擊更新時,它似乎並沒有更新實體。
感謝,
泰Rozak
你取消在'eds1_Updating'處理程序更新(通過設置'e.Cancel = TRUE;')? – jadarnel27