I'm trying to datagrid buttoncolumn of images show a popup window when clicked. I can create it when using the traditional pushbutton, but once I change the button to an image error results as follows:
"InvalidCastException: Specified cast is not valid." for line: "Dim deleteButton As ImageButton = e.Item.Cells(7).Controls(0)"
This is what I've got:
Datagrid's button column:
<asp:ButtonColumn Text="<img _ src="images/edit.jpg" _ border="0" />" CommandName="Delete" />
aspx page:
Sub dgResult_ItemDataBound(ByVal sender As Object, _
ByVal e As DataGridItemEventArgs)
If e.Item.ItemType <> ListItemType.Header And _
e.Item.ItemType <> ListItemType.Footer Then
Dim deleteButton As ImageButton = e.Item.Cells _
(7).Controls(0)
deleteButton.Attributes("onclick") _
= "javascript:return " & _
"confirm('Your are about to delete this _
record. Do you want to proceed?')"
End If
End Sub
BTW, I've tried both imagebutton and button for the codebehind but same error returns. Any advice? thank
"InvalidCastException: Specified cast is not valid." for line: "Dim deleteButton As ImageButton = e.Item.Cells(7).Controls(0)"
This is what I've got:
Datagrid's button column:
<asp:ButtonColumn Text="<img _ src="images/edit.jpg" _ border="0" />" CommandName="Delete" />
aspx page:
Sub dgResult_ItemDataBound(ByVal sender As Object, _
ByVal e As DataGridItemEventArgs)
If e.Item.ItemType <> ListItemType.Header And _
e.Item.ItemType <> ListItemType.Footer Then
Dim deleteButton As ImageButton = e.Item.Cells _
(7).Controls(0)
deleteButton.Attributes("onclick") _
= "javascript:return " & _
"confirm('Your are about to delete this _
record. Do you want to proceed?')"
End If
End Sub
BTW, I've tried both imagebutton and button for the codebehind but same error returns. Any advice? thank