2

我刚刚问了一个关于这个主题的问题;所有行在 Gridview 中都有一个删除按钮

我有一张简单的桌子AVUKAT

列 --> HESAP, MUSTERI,AVUKAT

我在 Gridview 中显示数据。

我激活AutoGenerateDeleteButton

在此处输入图像描述

但是当我单击一行的删除按钮时,我收到了这样的错误。

Server Error in '/' Application.
Deleting is not supported by data source 'GridviewDataSource' unless DeleteCommand is specified.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.NotSupportedException: Deleting is not supported by data source 'GridviewDataSource' unless DeleteCommand is specified.

Source Error:

An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.

单击删除按钮时激活了哪个功能?

这个函数的代码应该是什么?

4

3 回答 3

2

看看这篇 MSDN 文章:http: //msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.sqldatasource.deletecommand.aspx#Y725

它描述了设置 SQLDataSource 以从数据库中删除数据。

更新

您的 SQLDataSource 缺少“删除参数”(MSDN 链接)。

更新您的 SQLDataSource 以包含 DeleteParameters,如下所示(您需要更新 ControlParameters 的 ConnectionString 和 ControlID 等内容):

<asp:SqlDataSource
   id="SqlDataSource1"
   runat="server"
   ConnectionString="myConnectionString"
   SelectCommand="SELECT * FROM [AVUKAT] ORDER BY [MUSTERI]" 
   DeleteCommand="DELETE FROM [AVUKAT] WHERE MUSTERI = @MUSTERI AND AVUKAT = @AVUKAT AND HESAP = @HESAP">
   <DeleteParameters>
      <asp:ControlParameter Name="MUSTERI" ControlId="DropDownListID" PropertyName="SelectedValue" />
      <asp:ControlParameter Name="AVUKAT" ControlId="DropDownListID" PropertyName="SelectedValue" />
      <asp:ControlParameter Name="HESAP" ControlId="DropDownListID" PropertyName="SelectedValue" />
   </DeleteParameters>
</asp:SqlDataSource>
于 2011-02-11T13:26:55.790 回答
1

除此之外,请记住在您将运行此删除命令的表中使用主键。因为在没有 Primary key 的情况下,delete 命令将引发异常,因为如果多行具有相同的值,则生成的查询可能不明确(事实上,除非您的表有,否则您将无法附加内置的 DELETE 命令一个主键。)

于 2011-06-22T17:10:02.893 回答
0

您需要按照本教程中的描述实现 RowDeleting 事件。

于 2011-02-11T13:26:11.550 回答