数据源' SqlDataSource1'不支持删除.除非指定DeleteCommand [英] Deleting is not supported by data source 'SqlDataSource1' unless DeleteCommand is specified

查看:93
本文介绍了数据源' SqlDataSource1'不支持删除.除非指定DeleteCommand的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在 GridView1 中有一个ASP按钮链接,该链接应在单击时从数据库表中删除一个项目,并且我收到此错误消息:

I have an ASP button link in GridView1 that should delete an item from a db table on click, and I am getting this error message:

Deleting is not supported by data source 'SqlDataSource1' unless DeleteCommand is specified. 

这是代码:

VB.NET

Protected Sub GridView1_RowCommand(sender As Object, e As GridViewCommandEventArgs) Handles GridView1.RowCommand


    If e.CommandName.Equals("Delete") Then


        Dim rowIndex As Integer = Convert.ToInt32(e.CommandArgument)
        Dim rowID As String = e.CommandArgument.ToString()
        Dim conn As New SqlConnection("Data Source=BRIAN-PC\SQLEXPRESS;Initial Catalog=master_db;Integrated Security=True;")
        Dim cmd As New SqlCommand("DELETE content WHERE content_id=@rowID", conn)

        cmd.Parameters.AddWithValue("@rowID", rowID)

        conn.Open()
        cmd.ExecuteNonQuery()
        conn.Close()


    End If

End Sub

ASP

<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" CellPadding="4" DataSourceID="SqlDataSource1" ForeColor="#333333" GridLines="None" ViewStateMode="Enabled">
        <AlternatingRowStyle BackColor="White" ForeColor="#284775" />
        <Columns>
            <asp:BoundField DataField="content_name" HeaderText="Content Name" SortExpression="content_name">
            </asp:BoundField>
            <asp:BoundField DataField="content_type" HeaderText="Content Type" SortExpression="content_type">
            </asp:BoundField>
            <asp:buttonfield buttontype="Link" commandname="Delete" text="Delete"> 
             <ItemStyle HorizontalAlign="Center" VerticalAlign="Middle" />
            </asp:buttonfield>
             <asp:TemplateField HeaderText=" ">
            <ItemTemplate>
            <asp:LinkButton ID="lnkDownload" runat="server" Text="Download" OnClick="lnkDownload_Click" ></asp:LinkButton>
            </ItemTemplate>
            </asp:TemplateField>
        </Columns>
        <EditRowStyle BackColor="#999999" />
        <FooterStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" />
        <HeaderStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" />
        <PagerStyle BackColor="#284775" ForeColor="White" HorizontalAlign="Center" />
        <RowStyle BackColor="#F7F6F3" ForeColor="#333333" />
        <SelectedRowStyle BackColor="#E2DED6" Font-Bold="True" ForeColor="#333333" />
        <SortedAscendingCellStyle BackColor="#E9E7E2" />
        <SortedAscendingHeaderStyle BackColor="#506C8C" />
        <SortedDescendingCellStyle BackColor="#FFFDF8" />
        <SortedDescendingHeaderStyle BackColor="#6F8DAE" />
    </asp:GridView>

根据我的阅读,您需要为 SQLDataSource1 指定一个DELETE命令.

From what I read you need to specify a DELETE command for SQLDataSource1.

我该怎么办?

推荐答案

您必须输入asp代码:

You have to put in the asp code :

<asp:ButtonColumn CommandName="Delete" Text="Delete"></asp:ButtonColumn>

此致.

这篇关于数据源&amp;#39; SqlDataSource1&amp;#39;不支持删除.除非指定DeleteCommand的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆