Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

datagrid image button column confirmation pop-up

Status
Not open for further replies.

hamking01

Programmer
May 30, 2004
238
US
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="&lt;img _ src=&quot;images/edit.jpg&quot; _ border=&quot;0&quot; /&gt;" 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
 
Code:
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 = ctype(e.Item.FindControl("btnDelete"), ImageButton)
   deleteButton.Attributes.Add("onclick",
         "javascript:return " & _
         "confirm('Your are about to delete this _ 
         record.  Do you want to proceed?')")
    End If
End Sub

"...we both know I'm training to become a cagefighter...see what happens if you try 'n hit me..."
 
My datagrid's: <asp:ButtonColumn Text="&lt;img _ src=&quot;images/edit.jpg&quot; _ border=&quot;0&quot; /&gt;" CommandName="Delete" />

doesn't reference button name.
 
i guess i may have used my own image button template column to do this one...

"...we both know I'm training to become a cagefighter...see what happens if you try 'n hit me..."
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top