我只是问了一个关于这个问题的问题; All Row has a Delete Button in 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.


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

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

最佳答案

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

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

更新资料

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

更新您的SQLDataSource以包含DeleteParameters,如下所示(您需要更新诸如ControlStrings的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>

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

10-17 01:19