My delete command isn’t deleting. When I click the delete button, I see the Get and Post events fire, but no changes are reflected in my database, or on the page. If I assign a default value to the asp:Parameter the default value gets passed every time, and if it happens to exist in the database, the delete command evaluates properly and deletes the record.
<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>
I feel like this is an obvious issue like a typo or something and I just can’t find it, but I can’t say for sure. Anything jump out as wrong?
Listview that displays/deletes data:
<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>
Try this code
Use
DataKeyNamesproperty for listview.ListView.DataKeyNames Property