这是我的例子,你看看吧,不知道有没有帮助
<% @ import namespace="system.data" %>
<% @ import namespace="system.data.oledb" %>
<html>
<head>
<title>DATAGRID删除</title>
</head>
<body>
<h3>删除数据</h3>
<form id="Form1" method="post" runat="server">

<asp:Label ID="label1" Runat="server" />
<hr>
<asp:DataGrid ID="grid1" Runat="server" HeaderStyle-BackColor="blue" HeaderStyle-ForeColor="yellow"
 ItemStyle-BackColor="white" ItemStyle-ForeColor="black" Width="720" DataKeyField="userno" OnDeleteCommand="del">

 <Columns>
 <asp:ButtonColumn Text="删除" CommandName="delete" />
 </Columns>
 </asp:DataGrid>
</form>

<script language="vb" runat="server">
dim objconn as oledbconnection
dim objcmd as oledbdataadapter
dim objds as dataset
dim strsql as string

sub page_load(sender as object,e as eventargs)
show1()
end sub


sub del(s as object, e as datagridcommandeventargs)
dim objmd as oledbcommand
dim strno as string
strno=grid1.datakeys.item(e.item.itemindex)
strsql="delete * from members where userno='" & strno & "'"
objconn=new oledbconnection(" Provider=Microsoft.Jet.OLEDB.4.0; Data Source=" & Server.MapPath("db1.mdb"))
                objmd=new oledbcommand(strsql,objconn)
objmd.connection.open()
try
objmd.executenonquery()
label1.text="<font color='red'>删除数据(" & strno & ")" & "成功</font>"
catch exp as oledbexception
label1.text="<font color='red'>删除数据(" & strno & ")" & "有误,请重试一次</font>"
end try
objmd.connection.close()
        show1()
end sub

sub show1()
strsql="select  * from members"
objconn=new oledbconnection("provider=microsoft.jet.oledb.4.0;data source=" & server.mappath("db1.mdb"))
objcmd=new oledbdataadapter(strsql,objconn)
objds=new dataset()
objcmd.fill(objds,"members")
grid1.datasource=objds.tables("members").defaultview
grid1.databind()
end sub

</script>
</body>
</html>

解决方案 »

  1.   

    add the following 
    if(e.CommandName=="del")
      

  2.   

    private void InitializeComponent()
    {    
    this.studentGrid.SortCommand += new System.Web.UI.WebControls.DataGridSortCommandEventHandler(this.DataGridSorting);
    this.studentGrid.DeleteCommand += new System.Web.UI.WebControls.DataGridCommandEventHandler(this.delete);
    this.Load += new System.EventHandler(this.Page_Load); }private void delete(object source, System.Web.UI.WebControls.DataGridCommandEventArgs e)
    {

    }
      

  3.   

    怎么不用DataGrid的删除按钮列来实现
    如下:
    .aspx
    <asp:ButtonColumn Text="删除" CommandName="Delete"></asp:ButtonColumn>
    .cs
    private void DataGrid2_DeleteCommand(object source, System.Web.UI.WebControls.DataGridCommandEventArgs e)
    {
       response.write(e.item.cells(0).text)
    }
      

  4.   

    不要改该CommandName,就用默认的Delete
    还有不要使用按钮方式,按了没反应,我是这样的。谁知道为什么。快来告诉我!
      

  5.   

    <asp:button commandname=del runat=server text=删除/>
    ------------------------------>
    <asp:button commandname=Delete runat=server text=删除/>
    或指定
    datagrid1.DeleteCommandName = Del
      

  6.   

    试试这样吧:
    <asp:ButtonColumn Text="删除" CommandName="Delete">
        <HeaderStyle Wrap="False" HorizontalAlign="Center"></HeaderStyle>
        <ItemStyle Wrap="False" HorizontalAlign="Center"></ItemStyle>
    </asp:ButtonColumn>后台代码:
    Private Sub dgrdgroup_DeleteCommand(ByVal source As Object, ByVal e As System.Web.UI.WebControls.DataGridCommandEventArgs) Handles dgrdgroup.DeleteCommand    response.write(e.item.cells(0).text)
    end sub