Home > Archive > ASP .NET Webcontrols > April 2005 > Confirm Delete in DataGrid
You are viewing an archived Text-only version of the thread.
To view this thread in it's original format and/or if you want to reply to
this thread please [click here]
| Author |
Confirm Delete in DataGrid
|
|
| Amelyan 2005-04-29, 9:00 pm |
| I found an example (below) in www.codeproject.com showing how to enable
DataGrid's delete buttons with confirmation. However, the example didn't
explain why the complicated if-condition is the way it is.
I tried just having the one line of code that adds confirmation script
without if-condition. However, this didn't work properly. DataGrid would
delete items even though I clicked Cancel in confirmation dialog.
Could anyone explain why the if-condition should be the way it is below in
order for the confirmation to work properly in DataGrid?
Thanks,
Amelyan
//In the DataGrid onItemDataBound method, add the following:
if ( e.Item.ItemType == ListItemType.AlternatingItem
|| e.Item.ItemType == ListItemType.Item
|| e.Item.ItemType == ListItemType.SelectedItem )
{
e.Item.Cells[0].Attributes.Add( "onClick", "return confirm('Are you
sure you wish to delete this record?');");
}
//* Note the magic number [0] should be the column that the button is
located.
| |
| Steve C. Orr [MVP, MCSD] 2005-04-30, 9:00 pm |
| This article shows how you can confirm a delete in a datagrid:
http://www.dotnetjunkies.com/HowTo/...3EB07C94A8.dcik
--
I hope this helps,
Steve C. Orr, MCSD, MVP
http://Steve.Orr.net
"Amelyan" <bamelyan@wi.rr.com> wrote in message
news:%23ZSGK7PTFHA.2520@TK2MSFTNGP09.phx.gbl...
>I found an example (below) in www.codeproject.com showing how to enable
>DataGrid's delete buttons with confirmation. However, the example didn't
>explain why the complicated if-condition is the way it is.
>
> I tried just having the one line of code that adds confirmation script
> without if-condition. However, this didn't work properly. DataGrid would
> delete items even though I clicked Cancel in confirmation dialog.
>
> Could anyone explain why the if-condition should be the way it is below in
> order for the confirmation to work properly in DataGrid?
>
> Thanks,
> Amelyan
>
> //In the DataGrid onItemDataBound method, add the following:
>
> if ( e.Item.ItemType == ListItemType.AlternatingItem
> || e.Item.ItemType == ListItemType.Item
> || e.Item.ItemType == ListItemType.SelectedItem )
> {
> e.Item.Cells[0].Attributes.Add( "onClick", "return confirm('Are you
> sure you wish to delete this record?');");
> }
> //* Note the magic number [0] should be the column that the button is
> located.
>
>
|
|
|
|
|