Confirm delete of record

I

Iain

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
 
M

Mark Rae

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.
 
I

Iain

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
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,766
Messages
2,569,569
Members
45,042
Latest member
icassiem

Latest Threads

Top