我遇到了这个问题,我在详细信息视图中添加了一个模板字段/按钮,该模板字段/按钮将删除gridview中的记录。我有好几页都可以正常工作,除了其中一页。我的帐单页面上的SqlDataSource
删除命令与其他页面大不相同,我认为这是删除按钮实际上没有做任何事情而只是刷新页面的罪魁祸首。
我试图将delete命令添加到gridview,但是它正在删除所有记录。我添加了where Invoice.InvoiceId = @Invoice.InvoiceID
,但可能会收到标量变量错误,因为那里存在内部联接。
这是按钮代码
<ItemTemplate>
<asp:Button ID="deleteButton" runat="server" CommandName="Delete" Text="Delete"
OnClientClick="return confirm('Are you sure you want to delete this user?');" />
</ItemTemplate>
</asp:TemplateField>
这是SqlDataSource
详细信息查询
<asp:SqlDataSource ID="SqlDataSourceInvoiceDetails" runat="server" ConflictDetection="CompareAllValues"
ConnectionString="<%$ ConnectionStrings:PurchaseOrderConnectionString %>"
DeleteCommand="DELETE FROM [Invoice] WHERE [InvoiceId] = @original_InvoiceId AND (([InvoiceNumber] = @original_InvoiceNumber) OR
([InvoiceNumber] IS NULL AND @original_InvoiceNumber IS NULL)) AND (([PurchaseDate] = @original_PurchaseDate) OR ([PurchaseDate]
IS NULL AND @original_PurchaseDate IS NULL)) AND (([InvoiceAmount] = @original_InvoiceAmount) OR ([InvoiceAmount] IS NULL AND
@original_InvoiceAmount IS NULL)) AND
(([PoNumber] = @original_PoNumber) OR ([PoNumber] IS NULL AND @original_PoNumber IS NULL))"
这是另一个页面上的查询示例,该页面实际上删除了值
<asp:SqlDataSource ID="SqlDataSourceDetails" runat="server" ConnectionString="<%$ ConnectionStrings:PurchaseConnectionString %>"
DeleteCommand="DELETE FROM PurchaseOrder WHERE (PoId = @POId)
删除命令/按钮也将弹出对话框消息,并仅刷新页面。我试过运行命令字段,而不是模板字段和相同的东西。如果代码看起来很奇怪,请提前抱歉。我走了一半,正在尝试使功能正常。