ASP.NET 中的 Gridview 删除按钮
我刚刚问了一个关于这个主题的问题; 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.
单击删除按钮时会激活哪个功能?
这个函数的代码应该是什么?
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
.
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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
看一下这篇 MSDN 文章: http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.sqldatasource.deletecommand.aspx#Y725
它描述了如何设置 SQLDataSource 以从数据库中删除数据。
更新
您的 SQLDataSource 缺少“删除参数”(MSDN 链接)。
更新 SQLDataSource 以包含 DeleteParameters,如下所示(您需要更新 ControlParameters 的 ConnectionString 和 ControlID 等内容):
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):
除此之外,请记住在将运行此删除命令的表中使用主键。原因在缺少主键的情况下,删除命令将引发异常,因为如果多行具有相同的值,则生成的查询可能不明确
(事实上,除非您的表有主键,否则您将无法附加内置 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. )
您需要按照本教程中的说明实现 RowDeleting 事件。
You need to implement the RowDeleting event as described in this tutorial.