gridview 删除记录
aspx文件
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="false" Height="194px" Width="703px" AllowPaging="True" OnPageIndexChanging="GridView1_PageIndexChanging" OnRowCommand="GridView1_RowCommand" PageSize="3">
<Columns>
<asp:TemplateField>
<ItemTemplate>
<table style="width: 681px">
<tr>
<td style="width: 111px">
<%#Eval("productname")%>
</td>
<td style="width: 114px">
<asp:Image ID="Image1" runat="server" ImageUrl='<%#"../"+Eval("productsltimg") %>' Width="110" Height="83" />
</td>
<td style="width: 277px">
<%#Eval("productdate")%>
</td>
<td>
<asp:HyperLink ID="HyperLink1" runat="server" NavigateUrl='<%#"~/productinfo.aspx?pid="+Eval("productid") %>' Target="_blank">
查看信息
</asp:HyperLink>
</td>
<td>
<asp:HyperLink ID="HyperLink2" runat="server" NavigateUrl='<%#"admin_modfiyproduct.aspx?pid="+Eval("productid") %>'>
修改
</asp:HyperLink>
</td>
<td>
<asp:Button ID="Button2" runat="server" Text="删除" CommandName="del" CommandArgument='<%# bind("productid") %>' />
</td>
</tr>
</table>
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
//
cs文件
protected void GridView1_RowCommand(object sender, GridViewCommandEventArgs e)
{
int index = Convert.ToInt32(e.CommandArgument);
DataSet myds = null;
if (e.CommandName == "del")
{
myds = DbHelperaAce.DbHelperACE.Query("select * from productlist where productid=" + index + "");
File.Delete(Server.MapPath("../"+myds.Tables[0].Rows[0]["productimg"].ToString()));
File.Delete(Server.MapPath("../" + myds.Tables[0].Rows[0]["productsltimg"].ToString()));
myds = DbHelperaAce.DbHelperACE.Query("delete * from productlist where productid=" + index + "");
Response.Write("<script>alert('产品删除成功')</script>");
}
bindv();
}