GridView中绑定删除提示

<asp:GridView DataKeyNames="CategoryID" ID="GridView1" runat="server" AutoGenerateColumns="False" OnRowCommand="GridView1_RowCommand" OnRowDataBound="GridView1_RowDataBound" OnRowDeleted="GridView1_RowDeleted" OnRowDeleting="GridView1_RowDeleting">
<Columns>

<asp:BoundField DataField="CategoryID" HeaderText="CategoryID" />

<asp:BoundField DataField="CategoryName" HeaderText="CategoryName" />

<asp:TemplateField HeaderText="Select">

<ItemTemplate>

<asp:LinkButton ID="LinkButton1" CommandArgument='<%# Eval("CategoryID") %>' CommandName="Delete" runat="server">Delete</asp:LinkButton>

</ItemTemplate>

</asp:TemplateField>

</Columns>

</asp:GridView>




protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{

if (e.Row.RowType == DataControlRowType.DataRow)

{

LinkButton l = (LinkButton)e.Row.FindControl("LinkButton1"); 

l.Attributes.Add("onclick", "javascript:return " +

"confirm('Are you sure you want to delete this record " +

DataBinder.Eval(e.Row.DataItem, "CategoryID") + "')"); 

}

}



转自:http://www.highoncoding.com/Articles/138_GridView%20Confirm%20When%20Delete.aspx

你可能感兴趣的:(JavaScript,java)