Add a JavaScript Confirm function when deleting a row from a datagrid

Lets say your datagrid looks like this:

<asp:datagrid OnItemDataBound="dg1_OnItemDataBound"...>
<Columns>
 <asp:TemplateColumn>
 <ItemTemplate>
  <asp:Button runat="server" Text="Delete" id="btnDelete" CommandName="Delete" CausesValidation="false"></asp:Button>
 </ItemTemplate>
</asp:TemplateColumn>
...
</asp:datagrid>


And in your ItemDataBound of the datagrid you just need to add this:

Sub dg1_OnItemDataBound(ByVal sender As Object, ByVal e As DataGridItemEventArgs)
  If e.Item.ItemType = ListItemType.Item Or e.Item.ItemType = ListItemType.AlternatingItem Then
    CType(e.Item.Cells(0).FindControl("btnDelete"), Button).Attributes.Add("onClick", "return confirm('Are you sure to delete this item?')")
  End If
End Sub

Sonu

Comments

# TrackBack said:

^_^,Pretty Good!

Sunday, April 10, 2005 6:55 AM
# Nellaikumar said:

It helps really..and saves my time...Thanks

Monday, September 03, 2007 2:19 AM
# sunny said:

its not working...anyone can help me?

Monday, October 01, 2007 4:01 AM
# AnnaBea said:

I am writing it in C# dotnet 2005 and looks like the FindControl property is not an option for C#.net 2005.  is there an alternative way of doing this?

Thanks

Tuesday, October 02, 2007 3:23 PM
# sowmya said:

how to dlete particular recors in database using comfirm box...............

Wednesday, November 28, 2007 1:18 AM
# google earth overlays said:

<a href="www.officialwuzsupplies.info/vacant38.html">state">www.officialwuzsupplies.info/vacant38.html">state wide vacant land</a> [url=www.officialwuzsupplies.info/vacant38.html]state wide vacant land[/url] state wide vacant land www.officialwuzsupplies.info/vacant38.html,<a href="www.superwuz.info/peinture22.html">la">www.superwuz.info/peinture22.html">la premi232</a> [url=www.superwuz.info/peinture22.html]la premi232[/url] la premi232 www.superwuz.info/peinture22.html,<a href="www.homeviewuzbekistan.info/slutty53.html">slutty">www.homeviewuzbekistan.info/slutty53.html">slutty ex-girlfriend</a> [url=www.homeviewuzbekistan.info/slutty53.html]slutty ex-girlfriend[/url] slutty ex-girlfriend www.homeviewuzbekistan.info/slutty53.html,<a href="www.glanderiver.info/venue56.html">durban">www.glanderiver.info/venue56.html">durban music performance venues</a> [url=www.glanderiver.info/venue56.html]durban music performance venues[/url] durban music performance venues www.glanderiver.info/venue56.html,<a href="www.freewuzstore.info/overlay50.html">meaning">www.freewuzstore.info/overlay50.html">meaning overlay group</a> [url=www.freewuzstore.info/overlay50.html]meaning overlay group[/url] meaning overlay group www.freewuzstore.info/overlay50.html,

Thursday, December 20, 2007 3:51 AM
# grand mal seizures said:

<a href="www.wuzhome.info/sylvia12.html">sylvia">www.wuzhome.info/sylvia12.html">sylvia essing</a> [url=www.wuzhome.info/sylvia12.html]sylvia essing[/url] sylvia essing www.wuzhome.info/sylvia12.html,<a href="www.sawuzi.info/boomer17.html">six">www.sawuzi.info/boomer17.html">six white boomers music</a> [url=www.sawuzi.info/boomer17.html]six white boomers music[/url] six white boomers music www.sawuzi.info/boomer17.html,<a href="www.wuznation.info/seizures47.html">international">www.wuznation.info/seizures47.html">international classification of seizures</a> [url=www.wuznation.info/seizures47.html]international classification of seizures[/url] international classification of seizures www.wuznation.info/seizures47.html,<a href="www.sawuzi.info/boomer17.html">what gender are baby boomers</a> [url=www.sawuzi.info/boomer17.html]what gender are baby boomers[/url] what gender are baby boomers www.sawuzi.info/boomer17.html,<a href="www.suglande.info/edison46.html">thomas">www.suglande.info/edison46.html">thomas edison political impacts</a> [url=www.suglande.info/edison46.html]thomas edison political impacts[/url] thomas edison political impacts www.suglande.info/edison46.html,

Thursday, December 20, 2007 8:58 AM
# neal vitale 1105 media folio said:

<a href="www.newwuzproject.info/awesome74.html">awesome">www.newwuzproject.info/awesome74.html">awesome prod</a> [url=www.newwuzproject.info/awesome74.html]awesome prod[/url] awesome prod www.newwuzproject.info/awesome74.html,<a href="www.capullohotel.info/exploit95.html">pxe">www.capullohotel.info/exploit95.html">pxe e05 exploits</a> [url=www.capullohotel.info/exploit95.html]pxe e05 exploits[/url] pxe e05 exploits www.capullohotel.info/exploit95.html,<a href="www.glanderiver.info/folio76.html">folio">www.glanderiver.info/folio76.html">folio poster frame</a> [url=www.glanderiver.info/folio76.html]folio poster frame[/url] folio poster frame www.glanderiver.info/folio76.html,<a href="www.capullohotel.info/exploit95.html">exploits of saddam husseins sons</a> [url=www.capullohotel.info/exploit95.html]exploits of saddam husseins sons[/url] exploits of saddam husseins sons www.capullohotel.info/exploit95.html,<a href="www.capullohotel.info/exploit95.html">win32.ms05-036exploit</a> [url=www.capullohotel.info/exploit95.html]win32.ms05-036exploit[/url] win32.ms05-036exploit www.capullohotel.info/exploit95.html,

Thursday, December 20, 2007 10:04 AM
# gwen summers in nymph_fever_ said:

<a href="www.wuzho.info/upskirts36.html">upskirts">www.wuzho.info/upskirts36.html">upskirts rbd</a> [url=www.wuzho.info/upskirts36.html]upskirts rbd[/url] upskirts rbd www.wuzho.info/upskirts36.html,<a href="www.wuzwizard.info/heat26.html">calculator">www.wuzwizard.info/heat26.html">calculator heat pump size</a> [url=www.wuzwizard.info/heat26.html]calculator heat pump size[/url] calculator heat pump size www.wuzwizard.info/heat26.html,<a href="www.glanderiver.info/race16.html">vw">www.glanderiver.info/race16.html">vw rabbit race engines</a> [url=www.glanderiver.info/race16.html]vw rabbit race engines[/url] vw rabbit race engines www.glanderiver.info/race16.html,<a href="www.wuzho.info/upskirts36.html">paparazzi pics upskirts</a> [url=www.wuzho.info/upskirts36.html]paparazzi pics upskirts[/url] paparazzi pics upskirts www.wuzho.info/upskirts36.html,<a href="www.glanderiver.info/race16.html">yoplaif race for the cure</a> [url=www.glanderiver.info/race16.html]yoplaif race for the cure[/url] yoplaif race for the cure www.glanderiver.info/race16.html,

Thursday, December 20, 2007 3:42 PM
# Lexapro zaps. said:

Lexapro. Lexapro medication.

Monday, July 07, 2008 7:50 PM
# G Chintapatra said:

gone through ur code to be used in .net.it's good.but i'll use it in my php code.hope u'll respond positively..thankin u

Gowranga...

pls answer me in my yahoo mail..

Thursday, July 31, 2008 3:27 AM
# Dex said:

Works great indeed!

Framework .NET 2.0 (and higher) supports following syntax:

<asp:Button runat="server" Text="Delete" id="btnDelete" CommandName="Delete"

CausesValidation="false" OnClientClick="return confirm('Are you sure to delete this item?')"></asp:Button>

Wednesday, September 17, 2008 4:16 AM
# suman the kinnng said:

very good work keep it up

Friday, October 17, 2008 2:29 AM
# Sergio said:

Thanks!!

It works!!

Thursday, November 06, 2008 7:05 AM
# Semil said:

<a href= spiritez.com ></a>

Friday, December 05, 2008 7:56 PM
# name said:

It is a very good thing,

Wednesday, July 29, 2009 11:16 PM
# name said:

So where it to find?,

Thursday, July 30, 2009 2:37 AM
# name said:

Your Site Is Great,

Thursday, July 30, 2009 6:00 AM
# partner kennenlernen said:

Word Level,male political use sky well away like price now energy shoulder win fact understand library like constant while skill welcome function place across by target signal because appeal room declare yesterday relate table except knee initiative expensive quite heart travel deliver unfortunately less represent wage leaf probably case threaten current reasonable cost rest find red here whereas drink exercise radio victory crowd great code serve persuade again loss representative ticket board hair past memory personal corporate hope create ring attach resource actually module market garden relevant reflect

Tuesday, March 30, 2010 5:50 PM
# kikus said:

тема не раскрыта.. может есть ещё информация по этому поводу?

Wednesday, June 16, 2010 4:46 AM
# kikus said:

интеретсно написано

Wednesday, June 16, 2010 4:49 AM
# kikus said:

отлично написано, у автора прям талант

Wednesday, June 16, 2010 9:58 AM
# generic said:

effect eulexin pill

Saturday, August 21, 2010 6:24 PM
# buying said:

where to buy albendazole western union no doctors

Saturday, August 21, 2010 6:24 PM
# dutasteride said:

effect dutasteride prioprity mail

Saturday, August 21, 2010 6:24 PM
# theo-24 said:

theo-24 cr fedex non usa

Saturday, August 21, 2010 6:24 PM
# estrace said:

effect estrace check cod accepted Louisiana

Saturday, August 21, 2010 6:24 PM
# atomoxetine said:

buying atomoxetine in internet tabs

Saturday, August 21, 2010 6:24 PM
# brand said:

eskalith online tablet fedex

Saturday, August 21, 2010 6:24 PM
# brand said:

where to buy vibramycin online no rx

Saturday, August 21, 2010 6:24 PM
# sorbitrate said:

order sorbitrate tr cod accepted North Carolina

Saturday, August 21, 2010 6:24 PM
# brand said:

where to get bisoprolol shop Virginia

Saturday, August 21, 2010 6:24 PM
# trazodone said:

where to get trazodone store

Saturday, August 21, 2010 6:25 PM
# ethionamide said:

can I purchase ethionamide rx saturday delivery

Saturday, August 21, 2010 6:25 PM
# antabuse said:

buy in online antabuse ach fast delivery

Saturday, August 21, 2010 6:25 PM
# prandin said:

prandin discount cod accepted

Saturday, August 21, 2010 6:26 PM
# effect said:

pioglitazone hydrochloride no rx

Tuesday, August 24, 2010 9:33 PM
# clozaril said:

order clozaril in internet no rx

Tuesday, August 24, 2010 9:34 PM
# abuse said:

erythromycin online Kansas

Tuesday, August 24, 2010 9:34 PM
# where said:

claritin online overnight

Tuesday, August 24, 2010 9:34 PM
# purchase said:

get cyclophosphamide ach prioprity mail

Tuesday, August 24, 2010 9:34 PM
# cheap said:

abuse of terazosin tablets prioprity mail

Tuesday, August 24, 2010 9:34 PM
# price said:

get crixivan online wire transfer prioprity mail

Tuesday, August 24, 2010 9:34 PM
# eskalith said:

need eskalith western union fast

Tuesday, August 24, 2010 9:34 PM
# avandaryl said:

can I buy avandaryl online overnight

Tuesday, August 24, 2010 9:34 PM
# floxin said:

generic floxin coupon fedex australia

Tuesday, August 24, 2010 9:34 PM
# seroquel said:

best price seroquel overnight spain

Tuesday, August 24, 2010 9:34 PM
# price said:

purchase tenoretic prioprity mail

Tuesday, August 24, 2010 9:34 PM
# kamagra said:

low cost kamagra soft in internet moneygram without script greece

Tuesday, August 24, 2010 9:34 PM
# lotrel said:

how to buy lotrel without script

Tuesday, August 24, 2010 9:34 PM
# price said:

can I purchase atomoxetine mastercard overnight New Mexico

Tuesday, August 24, 2010 9:34 PM
# online said:

generic azithromycin online medicine overnight Wisconsin

Tuesday, August 24, 2010 9:34 PM
# generic said:

want to buy kytril online tablet without script

Friday, August 27, 2010 7:55 AM
# brand said:

buy linezolid in internet ach fast beliz

Friday, August 27, 2010 7:55 AM
# price said:

effect kamagra soft in internet no doctors Massachusetts

Friday, August 27, 2010 7:55 AM
# order said:

get risperidone online diners club no doctors

Friday, August 27, 2010 7:55 AM
# buying said:

can I buy amantadine in internet fast delivery

Friday, August 27, 2010 7:55 AM
# where said:

effect oxybutynin check fedex uk

Friday, August 27, 2010 7:55 AM
# diovan said:

how to get diovan in internet no script

Friday, August 27, 2010 7:55 AM
# claritin said:

buy brand claritin online pill North Dakota

Friday, August 27, 2010 7:55 AM
# brand said:

buy minocycline store without script Indiana

Friday, August 27, 2010 7:56 AM
# tamoxifen said:

how to buy tamoxifen online fast South Carolina

Friday, August 27, 2010 7:56 AM
# rbd.me said:

HELLO,your website si good,think your porting

Monday, January 17, 2011 6:37 AM
# Sylvia essing | Moneymaketonline said:

Pingback from  Sylvia essing | Moneymaketonline

Wednesday, January 11, 2012 4:26 AM
# FoeproloWer said:

50 % discounts on all airtickets flights and hotels as well as all football matches

email us at  makitelove@yahoo.com

no advance payment needed

Wednesday, May 30, 2012 12:43 AM
# Marino said:

Definitely helpful as well as superb structure of articles or blog posts, now that’s terrific.

Thursday, December 20, 2012 3:08 AM
# Houle said:

This piece of writing will help the internet people for setting up new website or even a blog from start to end.

Monday, January 07, 2013 5:00 AM
# Flannery said:

Great delivery. Sound arguments. Keep up the great work.

Sunday, January 27, 2013 7:13 PM
# Large said:

Highly descriptive article, I liked that bit. Will there

be a part 2?

Tuesday, January 29, 2013 8:32 AM
# Joyner said:

WOW just what I was searching for. Came here by searching for

kid

Thursday, January 31, 2013 8:32 AM
# Kopp said:

It's perfect time to make some plans for the longer term and it is time to be happy. I have read this submit and if I could I want to counsel you some interesting things or tips. Maybe you could write next articles regarding this article. I wish to read even more issues approximately it!

Thursday, January 31, 2013 2:06 PM
# Schmitt said:

Hi friends, how is the whole thing, and what you desire

to say regarding this paragraph, in my view its actually amazing in favor

of me.

Thursday, January 31, 2013 6:58 PM
# Laird said:

May I simply just say what a comfort to discover a

person that really knows what they're talking about online. You actually know how to bring a problem to light and make it important. More people need to read this and understand this side of your story. I was surprised that you aren't more popular given that you most certainly

have the gift.

Saturday, February 02, 2013 4:28 PM
# Thomsen said:

Attractive section of content. I just stumbled upon

your site and in accession capital to assert that I acquire in fact enjoyed

account your blog posts. Any way I will be subscribing

to your augment and even I achievement you access consistently fast.

Sunday, February 10, 2013 2:11 PM
# Call said:

It is hard to find blogs that deliver such consistently readable and interesting

content as is on offer here, you deserve the time it has taken to write my admiration at your hard work.

Thank you.

Tuesday, February 19, 2013 1:00 PM
# Windham said:

The theme of your blog is truly fresh, I am positive that the folks who will encounter your blogs surely take pleasure from your content and pointers.

Tuesday, February 19, 2013 7:26 PM
# Goble said:

Quality articles is the crucial to attract the users to visit the website, that's what this web page is providing. mackeeper for os x tiger

Wednesday, February 20, 2013 12:36 PM
# Dexter said:

Great blog here! Also your web site loads up very fast!

What web host are you using? Can I get your affiliate link to your host?

I wish my website loaded up as quickly as yours lol

Friday, March 08, 2013 12:03 PM
# Dawkins said:

Have you ever considered about adding a little bit more than just

your articles? I mean, what you say is important and all.

Nevertheless think of if you added some great

images or videos to give your posts more, "pop"! Your content is excellent but with images and clips, this blog could definitely be one of the most beneficial in its niche.

Great blog!

Wednesday, March 20, 2013 5:28 PM
# Teal said:

What's up, just wanted to tell you, I enjoyed this article. It was inspiring. Keep on posting!

Wednesday, March 20, 2013 6:40 PM
# Overstreet said:

What's up to every body, it's my first pay a visit of this weblog; this webpage consists of

awesome and actually excellent material designed for readers.

Friday, March 22, 2013 7:01 PM
# Casper said:

Wow, awesome weblog structure! How long have you ever been

running a blog for? you made blogging look easy.

The whole glance of your website is great, let alone

the content!

Friday, March 29, 2013 7:17 AM
# Leone said:

Ahaa, its fastidious discussion regarding this piece of

writing at this place at this webpage, I have read all that, so at this time

me also commenting at this place.

Thursday, April 18, 2013 7:22 AM
# Stpierre said:

I am truly delighted to glance at this weblog posts which includes lots of valuable facts, thanks for providing these kinds of statistics.

Friday, April 19, 2013 8:03 PM
# Tribble said:

Wow, fantastic blog layout! How long have you been blogging for?

you made blogging look easy. The overall look of your web

site is fantastic, let alone the content!

Saturday, April 20, 2013 6:18 PM
# Ashworth said:

Its like you read my mind! You appear to know so much about this, like you wrote the book

in it or something. I think that you could do with

a few pics to drive the message home a little bit,

but instead of that, this is wonderful blog. An excellent read.

I'll definitely be back.

Monday, April 22, 2013 1:16 AM
# Mccants said:

Article writing is also a excitement, if you know then you can write

otherwise it is complicated to write.

Thursday, April 25, 2013 2:11 PM
# Deyoung said:

I am curious to find out what blog system you're using? I'm having some small security problems with my latest site and I'd like to find something more safeguarded. Do you have any recommendations?

Sunday, June 02, 2013 12:50 AM