我的删除命令没有删除。当我单击删除按钮时,我看到 Get 和 Post 事件触发,但没有任何更改反映在我的数据库或页面上。asp:Parameter
如果我为每次传递的默认值分配一个默认值,并且如果它恰好存在于数据库中,则删除命令会正确评估并删除记录。
<asp:SqlDataSource
ID="AcknowledgementDataSource" runat="server"
ConnectionString="<%$ ConnectionStrings:ProductionDatabaseConnectionString1 %>"
SelectCommand="select tblHRM_Acknowledgements.AcknowledgementID, tblHRM_Acknowledgements.Acknowledger, lstduperoncontacts.Contact as Acknowledgee, tblHRM_Acknowledgements.Comment from tblHRM_Acknowledgements left join lstduperoncontacts on tblHRM_Acknowledgements.acknowledgee = lstDuperonContacts.contactid where Acknowledger in (select lstDuperonContacts.ContactID from lstDuperonContacts where lstDuperonContacts.email = @lblemail)"
InsertCommand="insert into tblHRM_Acknowledgements(Acknowledger, Acknowledgee, Comment) Select contactID, @ddlAck, @txtComment from lstDuperonContacts where email = @lblemail"
DeleteCommand="delete from tblHRM_Acknowledgements where tblHRM_Acknowledgements.AcknowledgementID = @AcknowledgementID">
<SelectParameters>
<asp:ControlParameter ControlID="lblemail" Name="lblemail" />
</SelectParameters>
<InsertParameters>
<asp:ControlParameter ControlID="lblemail" Name="lblemail" />
<asp:ControlParameter ControlId="ddlAcknowledgee" PropertyName="SelectedValue" Name="ddlAck" />
<asp:ControlParameter ControlID="txtComment" Name="txtComment" />
</InsertParameters>
<DeleteParameters>
<asp:Parameter Name="AcknowledgementID" />
</DeleteParameters>
</asp:SqlDataSource>
我觉得这是一个明显的问题,例如拼写错误或其他什么,我只是找不到它,但我不能肯定地说。有什么错误的吗?
显示/删除数据的列表视图:
<asp:ListView ID="ListView1" runat="server" DataSourceID="AcknowledgementDataSource">
<AlternatingItemTemplate>
<li style="">
<asp:HiddenField ID="AcknowledgementField" Value='<%# Eval("AcknowledgementID") %>' runat="server" />
Acknowledgee:
<asp:Label ID="AcknowledgeeLabel" runat="server"
Text='<%# Eval("Acknowledgee") %>' />
<br />
Comment:
<asp:Label ID="CommentLabel" runat="server" Text='<%# Eval("Comment") %>' />
<br />
<asp:Button ID="DeleteButton" runat="server" CommandName="Delete"
Text="Delete" />
</li>
</AlternatingItemTemplate>
<EmptyDataTemplate>
No data was returned.
</EmptyDataTemplate>
<ItemSeparatorTemplate>
<br />
</ItemSeparatorTemplate>
<ItemTemplate>
<li style="">
<asp:HiddenField ID="AcknowledgementField" Value='<%# Eval("AcknowledgementID") %>' runat="server" />
Acknowledgee:
<asp:Label ID="AcknowledgeeLabel" runat="server"
Text='<%# Eval("Acknowledgee") %>' />
<br />
Comment:
<asp:Label ID="CommentLabel" runat="server" Text='<%# Eval("Comment") %>' />
<br />
<asp:Button ID="DeleteButton" runat="server" CommandName="Delete"
Text="Delete" />
</li>
</ItemTemplate>
<LayoutTemplate>
<ul ID="itemPlaceholderContainer" runat="server" style="">
<li runat="server" id="itemPlaceholder" />
</ul>
<div style="">
</div>
</LayoutTemplate>
</asp:ListView>