方法一:
我在添加了模版列按钮,用到了按钮的onclick和 OnClientClick事件,在客户端点击事件提示确认,在服务端点击事件执行,现在是这个服务端事件不知道怎么获取gridview所选择行索引.
方法二:
要是直接用gridview的删除按钮,又会直接的执行RowDeleting事件,不会弹出删除确认.
=============================================================================
郁闷,好怀念我的datagrid啊!
我在添加了模版列按钮,用到了按钮的onclick和 OnClientClick事件,在客户端点击事件提示确认,在服务端点击事件执行,现在是这个服务端事件不知道怎么获取gridview所选择行索引.
方法二:
要是直接用gridview的删除按钮,又会直接的执行RowDeleting事件,不会弹出删除确认.
=============================================================================
郁闷,好怀念我的datagrid啊!
后台在GridView1_RowCommand事件里:
if (e.CommandName == "DeleteTheRecord")
{
int index = Convert.ToInt32(e.CommandArgument);
int a = Convert.ToInt32(GridView1.DataKeys[index].Value.ToString());
this.DeleteMethod(a);
}
<ItemStyle HorizontalAlign="Center"></ItemStyle>
<ItemTemplate>
<asp:LinkButton ID="btnDelete" runat="server" CausesValidation="false" CommandName="Delete" Text="删除"></asp:LinkButton>
</ItemTemplate>
</asp:TemplateField> protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
e.Row.Attributes["onmouseover"] = "javascript:this.style.backgroundColor='#eeeeee';";
e.Row.Attributes["onmouseout"] = "javascript:this.style.backgroundColor='#ffffff';"; LinkButton btnDel = (LinkButton)e.Row.Cells[7].Controls[1];
btnDel.Attributes.Add("onclick", "return confirm('确定要删除这个用户吗?');");
}
}
后台事件:protected void GridView1_RowCommand(object sender, GridViewCommandEventArgs e)
{
}
<ItemStyle HorizontalAlign="Center"></ItemStyle>
<ItemTemplate>
<asp:LinkButton ID="btnDelete" runat="server" CausesValidation="false" CommandName="Delete" Text="删除" onClientClick="return confirm('确定要删除吗?')"></asp:LinkButton>
</ItemTemplate>
</asp:TemplateField>