ItemUpdating 不使用 EntityDataSource 调用 DetailsView
我有一个绑定到实体数据源的详细信息视图,并尝试使用它来更新一些内容。但是当我按下“更新”按钮时,ItemUpdating 事件永远不会触发。
下面是代码:
<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 期间,我设置了 Datasource 的 where 属性,以便它查询正确的项目,这是我可以让它工作的唯一方法,但我不认为这是一个问题。
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
}
有什么想法为什么我的活动没有触发吗?我希望它触发的原因是当我单击更新时它似乎根本没有更新实体。
谢谢,
泰·罗扎克
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
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
在您的详细信息视图集上
On your detailsview set
确保页面上的
EnableViewState
未设置为 false。Make sure that
EnableViewState
on the page is not set to false.