Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > ASP.NET and ASP > ASP.NET 1.0 and 1.1 > ASP.NET 1.0 and 1.1 Basics
Password Reminder
Register
Register | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
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 tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
 
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old December 4th, 2006, 08:46 PM
Friend of Wrox
Points: 2,101, Level: 18
Points: 2,101, Level: 18 Points: 2,101, Level: 18 Points: 2,101, Level: 18
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jul 2003
Location: , , .
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

  #2 (permalink)  
Old December 5th, 2006, 02:15 AM
Friend of Wrox
Points: 1,935, Level: 17
Points: 1,935, Level: 17 Points: 1,935, Level: 17 Points: 1,935, Level: 17
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Aug 2004
Location: United Kingdom
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.
  #3 (permalink)  
Old December 5th, 2006, 12:43 PM
Friend of Wrox
Points: 2,101, Level: 18
Points: 2,101, Level: 18 Points: 2,101, Level: 18 Points: 2,101, Level: 18
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jul 2003
Location: , , .
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

  #4 (permalink)  
Old December 6th, 2006, 02:10 AM
Friend of Wrox
Points: 1,935, Level: 17
Points: 1,935, Level: 17 Points: 1,935, Level: 17 Points: 1,935, Level: 17
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Aug 2004
Location: United Kingdom
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.
 


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


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



All times are GMT -4. The time now is 01:19 PM.


Powered by vBulletin®
Copyright ©2000 - 2019, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.