除非指定了 DeleteCommand,否则数据源“SqlDataSource1”不支持删除操作。 
说明: 执行当前 Web 请求期间,出现未处理的异常。请检查堆栈跟踪信息,以了解有关该错误以及代码中导致错误的出处的详细信息。 异常详细信息: System.NotSupportedException: 除非指定了 DeleteCommand,否则数据源“SqlDataSource1”不支持删除操作。源错误: 执行当前 Web 请求期间生成了未处理的异常。可以使用下面的异常堆栈跟踪信息确定有关异常原因和发生位置的信息。  堆栈跟踪: 
[NotSupportedException: 除非指定了 DeleteCommand,否则数据源“SqlDataSource1”不支持删除操作。]
   System.Web.UI.WebControls.SqlDataSourceView.ExecuteDelete(IDictionary keys, IDictionary oldValues) +408
   System.Web.UI.DataSourceView.Delete(IDictionary keys, IDictionary oldValues, DataSourceViewOperationCallback callback) +85
   System.Web.UI.WebControls.GridView.HandleDelete(GridViewRow row, Int32 rowIndex) +713
   System.Web.UI.WebControls.GridView.HandleEvent(EventArgs e, Boolean causesValidation, String validationGroup) +820
   System.Web.UI.WebControls.GridView.OnBubbleEvent(Object source, EventArgs e) +88
   System.Web.UI.Control.RaiseBubbleEvent(Object source, EventArgs args) +37
   System.Web.UI.WebControls.GridViewRow.OnBubbleEvent(Object source, EventArgs e) +123
   System.Web.UI.Control.RaiseBubbleEvent(Object source, EventArgs args) +37
   System.Web.UI.WebControls.LinkButton.OnCommand(CommandEventArgs e) +89
   System.Web.UI.WebControls.LinkButton.RaisePostBackEvent(String eventArgument) +159
   System.Web.UI.WebControls.LinkButton.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String eventArgument) +10
   System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument) +13
   System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData) +170
   System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +2863
=======================================================================================================
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="newsAdmin.aspx.cs" Inherits="newsAdmin" %><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
    <title>新闻管理</title>
     <link href="Style.css" rel="stylesheet" type="text/css" />
<script language="javascript" type="text/javascript">
// <!CDATA[function P1_onclick() {}// ]]>
</script>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <p id="P1" class="style4" onclick="return P1_onclick()" style="left: -37px; behavior: url(newsAdmin.aspx);
            vertical-align: bottom; width: 95%; position: absolute; top: 13px; text-align: right">
            <img align="left" class="style3" src="image/newsCenter_r2_c1.jpg" />
            <a class="nav" href="newsAdminDetail.aspx?action=Insert"><span style="font-size: 10pt; color: #006699">添加</span></a>
            &nbsp;&nbsp;&nbsp;
            <asp:LoginStatus ID="LoginStatus2" runat="server" CssClass="nav" LogoutAction="Redirect"
                LogoutPageUrl="~/news.aspx" />
            &nbsp; &nbsp;</p>
        <br />
        <br />
        <br />
        <br />
        <br />
        <asp:LoginView ID="LoginView1" runat="server">
            <AnonymousTemplate>
                &nbsp;&nbsp; &nbsp;&nbsp;
                <img src="image/shou.jpg" />请先执行<asp:LoginStatus ID="LoginStatus1" runat="server"
                    LogoutPageUrl="~/newsLogin.aspx" />
                操作!
            </AnonymousTemplate>
            <LoggedInTemplate>
                <asp:GridView ID="GridView1" runat="server" AllowPaging="True" AutoGenerateColumns="False"
                    BorderWidth="0px" CellPadding="4" CellSpacing="1" CssClass="Forumline" DataKeyNames="news_id"
                    DataSourceID="SqlDataSource1" PageSize="15" Width="95%">
                    <Columns>
                        <asp:BoundField DataField="news_type" HeaderText="类别" SortExpression="news_type" />
                        <asp:BoundField DataField="news_date" DataFormatString="{0:d}" HeaderText="日期" SortExpression="news_date" />
                        <asp:HyperLinkField DataNavigateUrlFields="news_id" DataNavigateUrlFormatString="newsAdminDetail.aspx?new_id={0}"
                            DataTextField="news_subject" HeaderText="标题" />
                        <asp:TemplateField ShowHeader="False">
                            <ItemTemplate>
                                <asp:LinkButton ID="LinkButton1" runat="server" CommandName="Delete" OnClientClick="return confirm('确定要删除?&quot;)">删除</asp:LinkButton>
                            </ItemTemplate>
                            <ItemStyle Width="60px" />
                        </asp:TemplateField>
                    </Columns>
                </asp:GridView>
            </LoggedInTemplate>
        </asp:LoginView>
        <br />
        <br />
        <br />
        <br />
        <br />
        <br />
        <br />
        <br />
        <br />
        <br />
        <asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:ConnectionString %>"
            SelectCommand="SELECT * FROM [news] ORDER BY [news_date] DESC">
        </asp:SqlDataSource>
    
    </div>
    </form>
</body>
</html>
=============================================================================
不能删哦。。
求高手指教!!!
 

解决方案 »

  1.   

           <asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString=" <%$ ConnectionStrings:ConnectionString %>" 
                SelectCommand="SELECT * FROM [news] ORDER BY [news_date] DESC"> 
            </asp:SqlDataSource> 这里没有指定DeleteCommand是什么SQL语句,当然不能删啦!
    不知道你的后台代码如何,要不然你把删除列的CommandName="Delete"删掉,不过删掉也是应该不能删的!
      

  2.   

    提示已经很明白了,你要指定删除语句,否则它不知道怎么为你删除数据。就像要指定select语句一样