.aspx
......
OnDeleteCommand="DataGrid1_Delete"
......
<asp:ButtonColumn Text="删除" CommandName="Delete">
<ItemStyle Width="50px"></ItemStyle>
</asp:ButtonColumn>.aspx.cs
public void DataGrid1_Delete(object sender, DataGridCommandEventArgs e)
{

//相关代码
SqlConnection myConn=new SqlConnection(...);

string deletestr="...";
.....
SqlCommand mycommand=new SqlCommand(deletestr,myConn);
mycommand.Connection.Open();
mycommand.ExecuteNonQuery();
mycommand.Connection.Close();

....
}

解决方案 »

  1.   

    我的代码
    newsid = Request.Params["aaid"];

    try
    {
    sel="delete from  aa  WHERE aaid="+newsid;
    sqlCommand1=new System.Data.SqlClient.SqlCommand (sel,sqlConnection1);
    sqlCommand1.Connection.Open();
    sqlCommand1.ExecuteNonQuery();  
    sqlCommand1.Connection.Close();  sqlDataAdapter1.Fill(dataSet151);
    dgd1.DataBind();
    }
      

  2.   

    运行时  出错  “/WebApplication11”应用程序中的服务器错误。
    --------------------------------------------------------------------------------无法找到资源。说明: HTTP 404。您正在查找的资源(或者它的一个依赖项)可能已被移除,或其名称已更改,或暂时不可用。请检查以下 URL 并确保其拼写正确。 请求的 URL: /WebApplication11/WebFrom10.aspx
    --------------------------------------------------------------------------------
    版本信息: Microsoft .NET Framework 版本:1.1.4322.573; ASP.NET 版本:1.1.4322.573
      

  3.   

    DataGrid绑定的DataSet是与数据库断开的。所以最后得把它刷新一下再传回数据库
    这问题我也郁闷了好几天,看着页面上没有了,但数据库里还有。别习的用DataGrid,太麻烦,还不如普通的COMMAND,呢
    俺是刚学,不一定对,高手再指点
      

  4.   

    我也是菜鸟,想用  HyperLink  传一个参数id ,然后在aspx.cs 里用
    sel="delete from  aa  WHERE aaid="+newsid;
    sqlCommand1=new System.Data.SqlClient.SqlCommand (sel,sqlConnection1);
    sqlCommand1.Connection.Open();
    sqlCommand1.ExecuteNonQuery();  
    sqlCommand1.Connection.Close();  sqlDataAdapter1.Fill(dataSet151);
    dgd1.DataBind();
    删掉所选的记录,他老是出现
    “/WebApplication11”应用程序中的服务器错误。
    --------------------------------------------------------------------------------无法找到资源。说明: HTTP 404。您正在查找的资源(或者它的一个依赖项)可能已被移除,或其名称已更改,或暂时不可用。请检查以下 URL 并确保其拼写正确。 请求的 URL: /WebApplication11/WebFrom10.aspx
    --------------------------------------------------------------------------------
    版本信息: Microsoft .NET Framework 版本:1.1.4322.573; ASP.NET 版本:1.1.4322.573