Wrox Programmer Forums
|
ASP.NET 1.0 and 1.1 Basics ASP.NET discussion for users new to coding in ASP.NET 1.0 or 1.1. NOT for the older "classic" ASP 3 or the newer ASP.NET 2.0.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ASP.NET 1.0 and 1.1 Basics section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old December 4th, 2006, 08:46 PM
Friend of Wrox
 
Join Date: Jul 2003
Posts: 599
Thanks: 6
Thanked 3 Times in 3 Posts
Default Confirm in ItemDataBound

Hi All,

I'm trouble getting a javascript confirm to work in a datagrid.

Here is the front side code:

Code:
<asp:TemplateColumn ItemStyle-HorizontalAlign="Center" HeaderText="Delete">
<ItemTemplate>
<asp:ImageButton CommandName="Delete" ID="btnDelete" ImageUrl="/images/delete_cir.gif" Runat="server" />
</ItemTemplate>
</asp:TemplateColumn>
I pulled this code from 4GuysFromRolla but keep getting the error:
Specified cast is not valid.

Code:
Sub grdLeakRates_ItemDataBound(ByVal s As Object, ByVal e As DataGridItemEventArgs) Handles grdLeakRates.ItemDataBound
If e.Item.ItemType = ListItemType.Item Or e.Item.ItemType = ListItemType.AlternatingItem Then
Dim btnDelete As ImageButton = e.Item.Cells(0).Controls(0)
btnDelete.Attributes("onclick") = "javascript: return " & _
"confirm('Are you sure?')"
End If
End Sub
I know I'm not connecting this correclty but I've tried BoundColumn, ButtonColumn... and all kinds of other stuff.

Any help would be greatly appreciated.

Thanks,
Richard

 
Old December 5th, 2006, 02:15 AM
Friend of Wrox
 
Join Date: Aug 2004
Posts: 550
Thanks: 0
Thanked 1 Time in 1 Post
Default

Just use the code below which also uses a javascript function named ConfirmDelete() as below:


Dim imgButton As ImageButton
            If e.Item.ItemType = ListItemType.Item Or e.Item.ItemType = ListItemType.AlternatingItem Then
                imgButton = CType(e.Item.FindControl("btnDelete"), ImageButton)
                imgButton.Attributes.Add("onclick","javascript:ret urn ConfirmDelete();")

            End If



-----------------------------------------
JS Function (copy this in the HTML part)
-----------------------------------------

function ConfirmDelete()
        {
            if (confirm("Are you sure you want to delete this category?"))
                return true;
            else
                return false;

        }

Regards
Mike

Fortune favours the brave, so don't regret on missed oppurtunities.
 
Old December 5th, 2006, 12:43 PM
Friend of Wrox
 
Join Date: Jul 2003
Posts: 599
Thanks: 6
Thanked 3 Times in 3 Posts
Default

Hi Mike,

That worked! Really appreciate you taking the time to respond.

So the CType function casts the control as an image button?

Thank you,
Richard

 
Old December 6th, 2006, 02:10 AM
Friend of Wrox
 
Join Date: Aug 2004
Posts: 550
Thanks: 0
Thanked 1 Time in 1 Post
Default

Yup

CType is used for casting..........

Regards
Mike

Fortune favours the brave, so don't regret on missed oppurtunities.





Similar Threads
Thread Thread Starter Forum Replies Last Post
Datagrid ItemDataBound Event Problem Grahame2003 C# 1 December 3rd, 2011 03:10 AM
ItemDataBound to Grid Within Repeater rstelma ASP.NET 2.0 Professional 4 July 9th, 2008 02:45 AM
Datagrid ItemDataBound column widht eresina ASP.NET 1.0 and 1.1 Basics 0 August 10th, 2005 04:42 AM
confirm crmpicco Javascript How-To 2 February 7th, 2005 01:23 PM
DataGrid ItemDataBound Wyatt70 ADO.NET 2 November 22nd, 2004 03:31 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.