在gridview中通过css+jquery实现删除提示
时间:2011-06-14 来源:fc5110
以前:
在GridView中添加一个模板列:LinkButton.设置CommandName="Delete",OnClientClick="return confirm('确认要删除吗?');"
jquery效果
<asp:GridView ID="GridView1" runat="server" AllowSorting="True" AutoGenerateColumns="False"
PagerSettings-Visible="false" DataKeyNames="FamilyMembersID" CssClass="jqGrid"
OnSorting="gridViewList_Sorting" OnRowDataBound="gridViewList_RowDataBound" OnRowDeleting="gridViewList_RowDeleting">
<Columns>
<asp:TemplateField HeaderText="删除" ItemStyle-HorizontalAlign="Center">
<ItemTemplate>
<asp:Button ID="btnDel" runat="server" CommandName="Delete" CssClass="del ButtonDel" Text="删除"
ToolTip="删除操作" />
</ItemTemplate>
<HeaderStyle CssClass="alignCenter" Width="30px" />
</asp:TemplateField>
</Columns>
</asp:GridView>
后台:
protected void GridView1_RowDeleting(object sender, GridViewDeleteEventArgs e)
{
int j = Convert.ToInt32(GridView1.DataKeys[e.RowIndex].Value);
addb.DeleteADType(j);
GridView1.DataSource = addb.GetAdType().Tables[0];
GridView1.DataBind();
}
jquery代码:
$(function () {
$('.ButtonDel‘).each(function () {
$(this).click(function () {
return confirm("删除后无法恢复,请确认!");
});
});
});
实现效果: