ASP.NET 中的 Gridview 删除按钮

发布于 2024-10-17 06:10:44 字数 1168 浏览 2 评论 0原文

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

我有一个简单的表 AVUKAT

列 --> HESAPMUSTERIAVUKAT

我在 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.

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

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

I just asked a question about this subject; All Row has a Delete Button in Gridview

I have a simple table AVUKAT

Columns --> HESAP, MUSTERI, AVUKAT

And I show the data in a Gridview.

I activate AutoGenerateDeleteButton.

enter image description here

But when I click the Delete button for a row, I am getting an error like this.

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.

Which Function is activated when I click the delete button?

What should be the code of this function?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(3

沧桑㈠ 2024-10-24 06:10:44

看一下这篇 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>

Take a look at this MSDN article: http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.sqldatasource.deletecommand.aspx#Y725

It describes setting up the SQLDataSource to delete data from the database.

Update

Your SQLDataSource is missing "Delete Parameters" (MSDN Link).

Update your SQLDataSource to include DeleteParameters as follows (you'll need to update things like the ConnectionString and ControlIDs of the ControlParameters):

<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>
陈年往事 2024-10-24 06:10:44

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

Apart from this remember to use a primary key in your table on which you will be running this Delete command. Cause in the absence of Primary key , delete command will throw an exception as the query generated might be ambiguous if more than one row will have the same value
(In fact you wont be able to attach In-built DELETE command until unless your Table has a primary key. )

苦行僧 2024-10-24 06:10:44

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

You need to implement the RowDeleting event as described in this tutorial.

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