Best way to handle delete on Gridview

Last post 06-08-2009 4:32 PM by Pushkar. 3 replies.

Sort Posts:

  • Best way to handle delete on Gridview

    06-08-2009, 1:36 PM

    Can anyone tell me the best way to handle a confirmation for a delete on Gridviews?

     

    Thanks

  • Re: Best way to handle delete on Gridview

    06-08-2009, 1:47 PM
    Answer

    One way is to handle the RowDataBound event, and add an onclick attrinbute to the delete button, which calls a confirm('are you sure you want to delete?').

  • Re: Best way to handle delete on Gridview

    06-08-2009, 1:48 PM
    • Contributor
      5,452 point Contributor
    • CSharpSean
    • Member since 10-21-2006, 5:43 AM
    • Orlando, FL
    • Posts 915
    OnClientClick event of a Delete LinkButton,  OnClientClick = "return confirm('Are you sure you want to delete this record?');"
  • Re: Best way to handle delete on Gridview

    06-08-2009, 4:32 PM
    • Contributor
      5,709 point Contributor
    • Pushkar
    • Member since 02-17-2006, 2:27 AM
    • Vibrant Gujarat
    • Posts 1,085

    Hi

    You can call the javascript function on the OnClientClick event of the Control or you can directly call the confirmation script on the onClientClick event. 

    First way 

    <script language="javascript">

    function delconfirm()
        { 
                return confirm("Are you sure you want to delete this/these record/s?");
        }

    </script>

     <asp:TemplateField HeaderText="Delete">
                                                                <ItemStyle HorizontalAlign="Center" Width="5%" />
                                                                <ItemTemplate>
                                                                    <asp:ImageButton ID="btndelete" runat="server" CommandName="delete_record" CommandArgument='<%# Eval("id") %>'
                                                                        Height="20px" ImageUrl="~/images/button-delete.gif" Width="55px" OnClientClick="return delconfirm();" />

                                                                </ItemTemplate>
                                                                <HeaderStyle HorizontalAlign="Center" Width="5%" />
                                                            </asp:TemplateField>

    Second Way 

     <asp:LinkButton ID="lnkDelete" runat="server" OnClientClick="return confirm('Are you sure want to delete this item(s) ?')"></asp:LinkButton>

    “ There is no great genius without some touch of madness. ”


    Remember to click “Mark as Answer” on the post If you get answer from my post(s) !

    Thanks Guys
    ------------
    Pushkar M Rathod
Page 1 of 1 (4 items)