Professional Web Applications Themes

confirm before delete ? - ASP.NET Data Grid Control

how would i add a yes/no box for a delete button ? e.g. this is my code - If e.CommandSource.commandname = "Delete" Then mainid = e.Item.Cells(0).Text mi.Text = e.Item.Cells(0).Text Dim strConn As String = "server=********;uid=****************;pwd=******** *;database=************" Dim conn As New System.Data.SqlClient.SqlConnection(strConn) Dim DeleteCmd As String = "DELETE from diary Where ID =" & mainid Dim Cmd As New System.Data.SqlClient.SqlCommand(DeleteCmd, conn) Cmd.Parameters.Add(New System.Data.SqlClient.SqlParameter("ID", DataGrid1.DataKeys(CInt(e.Item.ItemIndex)))) conn.Open() Cmd.ExecuteNonQuery() conn.Close() datagridfill() End If currently it just deletes without asking! thanks mark...

  1. #1

    Default confirm before delete ?

    how would i add a yes/no box for a delete button ? e.g. this is my code -

    If e.CommandSource.commandname = "Delete" Then
    mainid = e.Item.Cells(0).Text
    mi.Text = e.Item.Cells(0).Text
    Dim strConn As String =
    "server=********;uid=****************;pwd=******** *;database=************"
    Dim conn As New System.Data.SqlClient.SqlConnection(strConn)
    Dim DeleteCmd As String = "DELETE from diary Where ID =" & mainid
    Dim Cmd As New System.Data.SqlClient.SqlCommand(DeleteCmd, conn)
    Cmd.Parameters.Add(New System.Data.SqlClient.SqlParameter("ID",
    DataGrid1.DataKeys(CInt(e.Item.ItemIndex))))
    conn.Open()
    Cmd.ExecuteNonQuery()
    conn.Close()
    datagridfill()
    End If

    currently it just deletes without asking!

    thanks

    mark


    mark Guest

  2. #2

    Default Re: confirm before delete ?

    Say that your column with your delete button is index 0, your button is a
    LinkButton named "lnkDelete". The common way of doing this would be:
    In ItemDataBound of the grid:

    Dim i as DataGridItem = e.Item
    i.Cells(0).FindControl("lnkDelete").Attributes.Add ("onclick","javascript:ret
    urn confirm('Do you really want to delete this record?')")

    If you are using a satandard Delete column and you dont know the name of the
    linkbutton, then try this:

    Dim i as DataGridItem = e.Item
    i.Cells(0).Controls(0).Attributes.Add("onclick","j avascript:return
    confirm('Do you really want to delete this record?')")

    You may need in this case to do Controls(1). I dont know why, but i have
    found sometimes the linkbutton is control(0) and sometimes its control(1).
    It USUALLY is index 0, so try that first.

    HTH.


    "mark" <markremove.com> wrote in message news:tu2rc.81$Fc.41newsfe4-win...
    > how would i add a yes/no box for a delete button ? e.g. this is my code -
    >
    > If e.CommandSource.commandname = "Delete" Then
    > mainid = e.Item.Cells(0).Text
    > mi.Text = e.Item.Cells(0).Text
    > Dim strConn As String =
    > "server=********;uid=****************;pwd=******** *;database=************"
    > Dim conn As New System.Data.SqlClient.SqlConnection(strConn)
    > Dim DeleteCmd As String = "DELETE from diary Where ID =" & mainid
    > Dim Cmd As New System.Data.SqlClient.SqlCommand(DeleteCmd, conn)
    > Cmd.Parameters.Add(New System.Data.SqlClient.SqlParameter("ID",
    > DataGrid1.DataKeys(CInt(e.Item.ItemIndex))))
    > conn.Open()
    > Cmd.ExecuteNonQuery()
    > conn.Close()
    > datagridfill()
    > End If
    >
    > currently it just deletes without asking!
    >
    > thanks
    >
    > mark
    >
    >

    Eidolon Guest

  3. #3

    Default Re: confirm before delete ?


    "Eidolon" <eidolonivanovich> wrote in message
    news:ueIyWlmPEHA.3216TK2MSFTNGP12.phx.gbl...
    > Say that your column with your delete button is index 0, your button is a
    > LinkButton named "lnkDelete". The common way of doing this would be:
    > In ItemDataBound of the grid:
    >
    > Dim i as DataGridItem = e.Item
    >
    i.Cells(0).FindControl("lnkDelete").Attributes.Add ("onclick","javascript:ret
    > urn confirm('Do you really want to delete this record?')")
    >
    > If you are using a satandard Delete column and you dont know the name of
    the
    > linkbutton, then try this:
    >
    > Dim i as DataGridItem = e.Item
    > i.Cells(0).Controls(0).Attributes.Add("onclick","j avascript:return
    > confirm('Do you really want to delete this record?')")
    >
    > You may need in this case to do Controls(1). I dont know why, but i have
    > found sometimes the linkbutton is control(0) and sometimes its control(1).
    > It USUALLY is index 0, so try that first.
    >
    > HTH.
    >
    thanks ill give it a go!

    mark


    mark Guest

Similar Threads

  1. Confirm before delete
    By Pixel Pusher in forum Macromedia Exchange Dreamweaver Extensions
    Replies: 1
    Last Post: November 10th, 05:47 AM
  2. Confirm Delete in DataGrid
    By in forum ASP.NET Data Grid Control
    Replies: 19
    Last Post: September 14th, 09:06 AM
  3. flash form and confirm delete
    By Ian O'Betz in forum Macromedia ColdFusion
    Replies: 7
    Last Post: March 1st, 05:05 PM
  4. Add Confirm to Delete button in repeater
    By Roger Twomey in forum ASP.NET Data Grid Control
    Replies: 1
    Last Post: June 5th, 12:28 AM
  5. confirm delete prompt
    By Oliver Jobson in forum Windows XP/2000/ME
    Replies: 1
    Last Post: July 6th, 09:21 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139