Delete confirmation

D

Dave

How can I add the confirmation dialog on record delete to the "Delete"
command column in DataGrid control?
 
C

Craig

Something like this should do the trick for you.

<code>
Private Sub TheGrid_ItemDataBound(ByVal sender As System.Object, ByVal e As
System.Web.UI.WebControls.DataGridItemEventArgs) Handles
TheGrid.ItemDataBound
Try
Select Case e.Item.ItemType
Case ListItemType.Item, ListItemType.AlternatingItem,
ListItemType.EditItem, ListItemType.SelectedItem
' change this value to the column value to match that of your datagrid's
column containing the delete linkbutton
Dim intYourCellThatHasTheDeleteLinkButton = 0
Dim lb as LinkButton =
GetLinkButton(e.Item.Cells(intYourCellThatHasTheDeleteLinkButton))
If Not lb Is Nothing Then
' add an onclick attribute that will prompt the user
' if the user selects ok, then the DeleteCommand event will fire.
' if the user selects cancel, then it will not
lb.Addributes.Add("onclick", "return confirm(""Are you sure you want to
delete this record?"");")
End If
End Select

Catch ex As Exception
' Your error handler here
End Try
End Sub

Function GetLinkButton(Cell as TableCell) as LinkButton
For Each ctl As Control In Cell.Controls
If TypeOf(ctl) Is LinkButton Then
Return DirectCast(ctl, LinkButton)
End If
Next
End Function
</code>

HTH
Craig
 

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

Forum statistics

Threads
473,764
Messages
2,569,566
Members
45,041
Latest member
RomeoFarnh

Latest Threads

Top