为gridview 加上删除 按钮

加按钮控件:

<asp:TemplateField ShowHeader="False">
                           <ItemStyle HorizontalAlign="Center" Width="40px" />
                                <ItemTemplate>
                                   <asp:LinkButton ID="LinkButton1" runat="server" CausesValidation="False" CommandName="Delete" OnClientClick="return confirm('你确认删除?');" Text="删除" Font-Size="12px" ForeColor="DimGray"></asp:LinkButton>
                                </ItemTemplate>
                          </asp:TemplateField>

 

 

 

后台代码为:

protected void GridView1_RowDeleting(object sender, GridViewDeleteEventArgs e)
    {
        //string strID =  .DataKeys[e.RowIndex].Value.ToString();
        string strID = GridView1.DataKeys[e.RowIndex].Value.ToString();
        string strSQL;
        strSQL = "Delete from BBF WHERE RecNumb='" + strID + "'";
        db.ExecuteOleDb(strSQL);

        ClientScript.RegisterStartupScript(GetType(), "Message", "<SCRIPT LANGUAGE='javascript'>alert('删除成功!');</script>");
        //Get_Gridview();
        Response.Redirect("BBF.aspx");
    }

 

posted on 2009-04-22 11:14  tongdengquan  阅读(224)  评论(0编辑  收藏  举报