第一种方式:
<a href='RoomDelete.aspx?rid=<%#Eval("RoomId") %>'>
<img src="images/delete.gif" alt="删除" style="border:0px;" onclick="return confirm('确定要删除吗?')" />
</a>
或者:
<asp:Button id="btnDelete" runat="server" OnClientClick="if(!confirm('你确定要删除吗?'))return false;"/>
或者:
<asp:Button id="btnDelete" runat="server" OnClientClick="return confirm('你确定要删除吗?');"/>
第二种方式:
<asp:TemplateField HeaderText="删除">
<ItemTemplate>
<asp:ImageButton ID="imgBtnDel" runat="server" ImageUrl="~/images/delete.gif" CommandArgument='<%#Eval("TypeId") %>' CommandName="testDel" />
</ItemTemplate>
</asp:TemplateField>
protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
ImageButton ibtn = e.Row.FindControl("imgBtnDel") as ImageButton;
ibtn.Attributes.Add("onclick", "return confirm('确定要删除吗?')");
}
}