ItemUpdating 不使用 EntityDataSource 调用 DetailsView

发布于 2024-12-20 14:10:34 字数 2178 浏览 0 评论 0原文

我有一个绑定到实体数据源的详细信息视图,并尝试使用它来更新一些内容。但是当我按下“更新”按钮时,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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

迎风吟唱 2024-12-27 14:10:34

在您的详细信息视图集上

    CausesValidation="false"

On your detailsview set

    CausesValidation="false"
吹梦到西洲 2024-12-27 14:10:34

确保页面上的 EnableViewState 未设置为 false。

Make sure that EnableViewState on the page is not set to false.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文