<asp:TemplateField> <ItemTemplate> <a id="linkDelete" runat="server" href="#" title="Confirm delete">Delete</a> <asp:Button runat="server" CommandName="Delete" ID="btnDelete" Style="display: none;" /> </ItemTemplate> </asp:TemplateField>
function confirmDeleteResult(v,m,f) { if( v) //user clicked OK $('#' + f.hidID).click(); }
//making the alert button for each delete link. protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e) { if (e.Row.RowType == DataControlRowType.DataRow) { // we are using a html anchor and a hidden asp:button for the delete HtmlAnchor linkDelete = (HtmlAnchor)e.Row.FindControl("linkDelete"); Button btnDelete = (Button)e.Row.FindControl("btnDelete"); //for each delete link - the corresponding submit buttons id will be passed to delete call back as a hidden field string prompt = "$.prompt('Are you sure you want to delete the selected item?" + "<input type=\"hidden\" value=\"{0}\" name=\"hidID\" />'" + ", {{buttons: {{ Ok: true, Cancel: false }}, callback: confirmDeleteResult}} ); return false; "; linkDelete.Attributes["onclick"] = string.Format(prompt, btnDelete.ClientID); } } //showing success message after delete protected void SqlDataSource1_Deleted(object sender, SqlDataSourceStatusEventArgs e) { //The promt function shl'd be called inside $(document).ready() function inorder to avoid //IE's "Operation aborted" error string prompt = "<script>$(document).ready(function(){{$.prompt('{0}!');}});</script>"; string message = string.Format(prompt, "The selected item has been deleted successfully."); ClientScript.RegisterStartupScript(typeof(Page), "alert", message); }
CSS | XHTML 1.0
Programmed by Anz