|
code
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
Confirm Delete in DataGridDataGrid'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.Cells[0].Attributes.Add( "onClick", "return confirm('Are you || e.Item.ItemType == ListItemType.SelectedItem ) { sure you wish to delete this record?');"); } //* Note the magic number [0] should be the column that the button is located. This article shows how you can confirm a delete in a datagrid:
http://www.dotnetjunkies.com/HowTo/1E7FEE4A-795C-4D33-A135-843EB07C94A8.dcik 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. > >
How do you display and process confirmation dialog?
Problem with ViewState HowTo Loading ActiveX dinamically at runtime ? Arrow keys and the datagrid... How to use Microsoft Rich TextBox control 6? Converting XMLDocument To String Rollover from Image Ready Short-cut to New chromeless aspx page ? how to use winform in IE Comma appended to textboxes when retrieving value! |
|||||||||||||||||||||||