62,046
社区成员
发帖
与我相关
我的任务
分享
<asp:ButtonField HeaderText="删除" Text="删除" CommandName="Delete">
<ItemStyle HorizontalAlign="Center" />
</asp:ButtonField>
protected void GV_RowCommand(object sender, GridViewCommandEventArgs e)
{
if (e.CommandName == "Delete")
{
string strSQL = "delete from TABBASPOSAGENT where usercard=123459";//这里的参数我是写死了,如果传递参数啊???
Database db = new Database();
db.ExecuteSQL(strSQL);
Response.Write("<script language=javascript>alert('删除成功!');</script>");
}
}
<asp:GridView ID="grd" CssClass="DIVGrid" runat="server" BackColor="White" BorderWidth="1px"
BorderColor="Gray" BorderStyle="Solid" CellPadding="3" Font-Size="9pt" GridLines="Horizontal"
HorizontalAlign="Left" Width="100%" Style="left: 34px; top: 240px" AllowPaging="True"
EmptyDataText="No data." AutoGenerateColumns="false" ShowFooter="True"
OnRowDataBound="grd_RowDataBound" OnRowCommand="grd_RowCommand"
OnRowEditing="grd_RowEditing" OnRowUpdating="grd_RowUpdating" OnRowCancelingEdit="grd_RowCancelingEidt"
OnRowDeleting="grd_RowDeleting" >
<asp:TemplateField>
<ItemTemplate>
<asp:ImageButton ID="ibtnDelete" runat="server" CausesValidation="false" CommandName="Delete" ImageUrl="../SysFrame/images/ButtonDelete.gif" />
</ItemTemplate>
</asp:TemplateField>
protected void grd_RowDeleting(object sender, GridViewDeleteEventArgs e)
{
string id = ((Label)grd.Rows[e.RowIndex].FindControl("lblid")).Text; //去id
string sql = "delete from tbUser where id='" + id + "'"; //组成sql
using (OleDbConnection conn = GetConn())
{
OleDbCommand cmd = new OleDbCommand(sql, conn);
cmd.ExecuteNonQuery();
}
this.BindGrid(this, EventArgs.Empty);
}
protected void gridview1_RowDeleting(object sender, GridViewDeleteEventArgs e)
{
int _Id = Convert.ToInt32(gridview1.DataKeys[e.RowIndex].Value);
//删除具体的sql代码
}