Alert to confirm deletes in the new GridView control

Discussion in 'ASP .Net Datagrid Control' started by dev648237923, Nov 17, 2006.

  1. dev648237923

    dev648237923 Guest

    I want to have an alert to confirm deletes in the GridView. I have seen
    posting for doing it in DataGrid but I can not get it to work in the new
    GridView. I tried in GridView1_RowCommand I tried something like:

    ((LinkButton)GridView1.SelectedRow.FindControl("lbDelete")).Attributes.Add(
    "onClick", "return confirm('Are you sure you want to delete this row?');");

    Any ideas would be appretiated!

    Thank you!
     
    dev648237923, Nov 17, 2006
    #1
    1. Advertising

  2. Hi dev648237923,

    If you're using TemplateField, it is convenient for us to customize the
    controls in the template. The code project article you mentioend use
    "RowDataBound" event to add the "confirm delete" javascript for the
    delete button. You can also do it through the "RowCreated" event.

    In addition, in ASP.NET 2.0, button or LinkButton control provide the
    "OnClientClick" property that can let you add client-side click script.
    Therefore, you can also add the "confirm deleting" script in the LinkButton
    or Button's "OnClientClick" property. e.g


    =========================
    <asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False"
    DataKeyNames="CategoryID"
    DataSourceID="SqlDataSource1">
    <Columns>
    <asp:TemplateField ShowHeader="False">
    ..............
    <ItemTemplate>
    .............................
    <asp:LinkButton ID="LinkButton2" runat="server"

    OnClientClick="if(confirm('Are you sure to
    delete this item?') == false){return false;}"

    CausesValidation="False" CommandName="Delete"
    Text="Delete"></asp:LinkButton>
    </ItemTemplate>
    </asp:TemplateField>
    ==============================

    Hope this also helps.

    Sincerely,

    Steven Cheng

    Microsoft MSDN Online Support Lead



    ==================================================

    Get notification to my posts through email? Please refer to
    http://msdn.microsoft.com/subscriptions/managednewsgroups/default.aspx#notif
    ications.



    Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
    where an initial response from the community or a Microsoft Support
    Engineer within 1 business day is acceptable. Please note that each follow
    up response may take approximately 2 business days as the support
    professional working with you may need further investigation to reach the
    most efficient resolution. The offering is not appropriate for situations
    that require urgent, real-time or phone-based interactions or complex
    project analysis and dump analysis issues. Issues of this nature are best
    handled working with a dedicated Microsoft Support Engineer by contacting
    Microsoft Customer Support Services (CSS) at
    http://msdn.microsoft.com/subscriptions/support/default.aspx.

    ==================================================



    This posting is provided "AS IS" with no warranties, and confers no rights.
     
    Steven Cheng[MSFT], Nov 20, 2006
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. MasterChief

    Multiple Deletes in Gridview

    MasterChief, Feb 7, 2006, in forum: ASP .Net
    Replies:
    4
    Views:
    7,609
    MasterChief
    Feb 7, 2006
  2. Dodo
    Replies:
    1
    Views:
    370
    Ron Natalie
    Aug 26, 2003
  3. Andy Fish

    alert() and confirm() function

    Andy Fish, Aug 14, 2003, in forum: Javascript
    Replies:
    7
    Views:
    146
    Jim Ley
    Aug 14, 2003
  4. Tasha's Dad

    Need to cancel a javascript alert/confirm box

    Tasha's Dad, Nov 4, 2004, in forum: Javascript
    Replies:
    5
    Views:
    316
    kaeli
    Nov 9, 2004
  5. Íõ•
    Replies:
    0
    Views:
    107
    Íõ•
    Jan 14, 2005
Loading...

Share This Page