Home All Groups Group Topic Archive Search About
Author
29 Apr 2005 9:02 PM
Amelyan
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.

Author
30 Apr 2005 6:50 PM
Steve C. Orr [MVP, MCSD]
This article shows how you can confirm a delete in a datagrid:
http://www.dotnetjunkies.com/HowTo/1E7FEE4A-795C-4D33-A135-843EB07C94A8.dcik

--
I hope this helps,
Steve C. Orr, MCSD, MVP
http://Steve.Orr.net


Show quoteHide quote
"Amelyan" <bamel***@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.
>
>