p2p.wrox.com Forums

p2p.wrox.com Forums (http://p2p.wrox.com/index.php)
-   ASP.NET 2.0 Basics (http://p2p.wrox.com/forumdisplay.php?f=136)
-   -   GridView Delete (http://p2p.wrox.com/showthread.php?t=55472)

DARSIN March 16th, 2007 09:04 AM

GridView Delete
 
I had a Image button on a gridview column and I want to display a confirm box before the delete event is fired.
I have used this code to achive it
void gridView_RowCreated(object sender,GridViewRowEventArgs e )
        {
            if (e.Row.RowType == DataControlRowType.DataRow)
            {

                ImageButton imgDelete = ((ImageButton)(e.Row.Cells[6].Controls[2]));
                if (imgDelete.CommandName.ToUpper() == "DELETE")
                {
                    string message = UserManagementRessources.DeleteConfirm;
                                        imgDelete.OnClientClick = "if ( confirm('" + message + "') ) { return true; } else { return false; };";

                }



            }
        }

but the RowDeleteing event is not fired


gbianchi March 16th, 2007 09:13 AM

hi there..

try with this script

Code:

    <script type="text/javascript">
        function ConfirmDelete(e)
        {
            if (!window.confirm("your confirm text here"))
            {
                e.returnValue = false;
                if (e.preventDefault)
                    e.preventDefault();
                    return false;
            }
        }
    </script>

and add this to your button
Code:

OnClientClick="ConfirmDelete(event);"
and it will work like a charm...

HTH

Gonzalo

================================================== =========
Read this if you want to know how to get a correct reply for your question:
http://www.catb.org/~esr/faqs/smart-questions.html
^^Took that from dparsons signature and he Took that from planoie's profile
================================================== =========
I programs achieved a new certification (can you say the same?):
WORKS ON MY MACHINE
http://www.codinghorror.com/blog/archives/000818.html
================================================== =========

DARSIN March 20th, 2007 06:53 AM

Thanks that was gr8



All times are GMT -4. The time now is 07:23 PM.

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