gpt4 book ai didi

c# - ASP.NET 中的 Gridview 删除按钮

转载 作者:行者123 更新时间:2023-11-30 22:40:59 25 4
gpt4 key购买 nike

我刚刚问了一个关于这个主题的问题; All Row has a Delete Button in Gridview

我有一个简单的表格AVUKAT

列 --> HESAP, MUSTERI, AVUKAT

然后我在 Gridview 中显示数据。

我激活 AutoGenerateDeleteButton

enter image description here

但是当我点击某行的删除按钮时,出现了这样的错误。

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.

当我点击删除按钮时激活了哪个功能?

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

最佳答案

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

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

更新

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

按如下方式更新您的 SQLDataSource 以包括 DeleteParameters(您需要更新 ControlParameters 的 ConnectionString 和 ControlIDs 等内容):

<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>

关于c# - ASP.NET 中的 Gridview 删除按钮,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4969428/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com