Confirm delete of record

Discussion in 'ASP .Net' started by Iain, Jan 23, 2007.

  1. Iain

    Iain Guest

    Hi All

    I am witing a web app using Delphi developer 2006 (C# app) and I have a
    datagrid. Excuse the numptyness of the question. I have a datagrid with
    the ability to Insert, Edit/Update and Delete records.

    The following is the datagrid definition

    <asp:datagrid id="Livery"
    runat="server"
    allowsorting="True"
    EnableViewState="true"
    itemstyle-verticalalign="top"
    headerstyle-font-bold="true"
    headerstyle-forecolor="white"
    headerstyle-backcolor="black"
    autogeneratecolumns="false"
    font-size="8pt"
    cellpadding="5"
    width="92%"
    onsortcommand="Livery_SortCommand"
    ondeletecommand="Livery_DeleteCommand"
    oneditcommand="Livery_EditCommand"
    onupdatecommand="Livery_UpdateCommand"
    oncancelcommand="Livery_CancelCommand">
    <EditItemStyle borderstyle="Dashed"
    bordercolor="#0000C0"
    backcolor="#FFFFC0">
    </EditItemStyle>
    <ItemStyle verticalalign="Top">
    </ItemStyle>
    <HeaderStyle font-bold="True"
    forecolor="White"
    backcolor="Black">
    </HeaderStyle>
    <Columns>
    <ASP:EditCommandColumn buttontype="PushButton"
    updatetext="Update"
    headertext="Edit"
    canceltext="Cancel"
    edittext="Edit">
    </ASP:EditCommandColumn>
    <ASP:BoundColumn datafield="LIVNAME"
    headertext="Livery Name">
    </ASP:BoundColumn>
    <ASP:BoundColumn datafield="LEADTIME"
    headertext="Lead Time">
    </ASP:BoundColumn>
    <ASP:ButtonColumn text="Delete"
    buttontype="PushButton"
    headertext="Delete"
    commandname="Delete">
    </ASP:ButtonColumn>
    </Columns>
    </asp:datagrid>

    The following is the Delete event which fires when I select the Delete
    Button.


    protected void Livery_DeleteCommand(object source,
    System.Web.UI.WebControls.DataGridCommandEventArgs e)
    {
    ..........
    switch(e.Item.ItemType)
    {
    case ListItemType.Item:
    case ListItemType.AlternatingItem:
    {
    Button btn = (Button)e.Item.Cells[0].Controls[0];
    btn.Attributes.Add("onclick",
    "return confirm('are you sure you want to delete this')");
    break;
    }
    }
    ..........
    Delete Record If Required
    ..........
    }


    This piece of code - I grabbed this off an example on the web - fires
    but I am not sure that it is what I want. Do I understand this
    correctly in that it is creating a button (called btn) and adding an
    onclick event to it.
    What I need is for the confirm to execute and return a value so that I
    can confirm the deleting of the record selected.
    Can anyone point me in the right direction ?

    Thanks in advance for any help offered

    Iain
    Iain, Jan 23, 2007
    #1
    1. Advertising

  2. Iain

    Mark Rae Guest

    "Iain" <> wrote in message
    news:...

    > What I need is for the confirm to execute and return a value so that I
    > can confirm the deleting of the record selected.


    If the user clicks "Cancel", the delete event won't fire.
    Mark Rae, Jan 23, 2007
    #2
    1. Advertising

  3. Iain

    Iain Guest

    Hi Mark

    Yes that is the cse.
    However, I am a paranoid developer with a number of numpty's as users
    and all I am trying to protect against is unneccessary deletion of
    records and I just want the user to confirm that this is actually the
    record they want to delete so I need this to fire and work

    Thanks

    Iain
    Iain, Jan 23, 2007
    #3
    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. Calvin Lai
    Replies:
    4
    Views:
    7,925
    Calvin Lai
    Feb 4, 2004
  2. Spongebob
    Replies:
    2
    Views:
    484
    Spongebob
    Feb 11, 2004
  3. Sandy
    Replies:
    1
    Views:
    7,199
    =?Utf-8?B?TWF1cmljaW9ERw==?=
    Jun 11, 2004
  4. Dexter
    Replies:
    2
    Views:
    492
    Dexter
    Oct 3, 2004
  5. Saravana
    Replies:
    1
    Views:
    513
    =?Utf-8?B?UHN5Y2hv?=
    Oct 4, 2004
Loading...

Share This Page