'VB
Private Sub DataGrid1_ItemCreated(sender As Object, e As System.Web.UI.WebControls.DataGridItemEventArgs)
Dim lit As ListItemType = e.Item.ItemType
If lit = ListItemType.Item Then
Dim btnDelete As Button = CType(e.Item.FindControl("btnDelete", Button)
btnDelete.Attributes.Add("OnClick", "javascript: return confirm('Are you sure you want to delete this record?');"
End If
End Sub 'DataGrid1_ItemCreated
Now I get this error:
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.NullReferenceException: Object reference not set to an instance of an object.
Source Error:
Line 219: If lit = ListItemType.Item Then
Line 220: Dim btnDelete As Button = CType(e.Item.FindControl("btnDelete", Button)
Line 221: btnDelete.Attributes.Add("OnClick", "javascript: return confirm('Are you sure you want to delete this record?');"
Line 222: End If
Still nothing! Error again.
I know what's wrong: It's looking at column 0, but it won't let me change it to column 1. What's the deal?
I must be stupid! Thia can't be that hard.
Private Sub DataGrid1_ItemCreated(sender As Object, e As System.Web.UI.WebControls.DataGridItemEventArgs)
Select Case e.Item.ItemType
Case ListItemType.Item, ListItemType.AlternatingItem, ListItemType.EditItem
Dim myTableCell As TableCell
myTableCell = e.Item.Cells(0)
Dim myDeleteButton As LinkButton
myDeleteButton = myTableCell.Controls(0)
myDeleteButton.Attributes.Add("onclick","return confirm('Are you Sure you want to delete this company?');"
I GOT IT! I GOT IT! I GOT IT! I GOT IT! I GOT IT! I GOT IT!
Here's the reason it did not work: I needed to change the lines in the DataGrid1_ItemCreated Event..
From
Dim myDeleteButton As LinkButton
myDeleteButton = myTableCell.Controls(0)
myDeleteButton.Attributes.Add("onclick","return confirm('Are you Sure you want to delete this company?');"
To
Dim mydeleteButton As LinkButton = e.Item.Cells(1).Controls(0)
myDeleteButton.Attributes.Add("onclick","return confirm('Are you Sure you want to delete this company?');"
I HAD to reference Cells(1), and not Cells(0).
Ahhhhhhhhhhhhhhhhh, no hair left, but project is 1 more step to finish.
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.