Solved

problem with deleting a row from datagrid after confirmation

Posted on 2004-10-19
7
596 Views
Last Modified: 2008-03-03

hi all ,

i wanted to delete a row from the datagrid after confiramtion .i have used the same way that is given in the below link .
http://builder.com.com/5100-6373-1049811.html#Listing%20E
but the form is being posted even after i click on cancel . can any one pls tell me why this is happening. i have written the delete code both in the ItemCommand and also in deleteCommand function and tried . but the form is begin posted back even after i click on cancel of confirm dialog box .

regards
ITkid.

0
Comment
Question by:ITkid
  • 2
7 Comments
 
LVL 28

Expert Comment

by:mmarinov
Comment Utility
Hi ITkid,


are you sure you have added this line exectly as it said:
l.Attributes.Add("onclick", "return confirm('Are you sure you want to delete this item?');")

Regards!
B..M
0
 
LVL 22

Expert Comment

by:CJ_S
Comment Utility
Show how you are calling the confirmation.

If it is javascript confirmation you have to use the return statement. For example

<a href="link.aspx" onClick="return confirm('Are you sure you want to remove this item?')">delete</a>

This way the link.aspx will only be executed after you click OK in the dialog. So, what does your code look like?
0
 
LVL 2

Accepted Solution

by:
dwcorwith earned 125 total points
Comment Utility
I just used the exact same code in my app.  I found an omission in the builder.com code you referenced.  Add the CommandName attribute to the linkbutton.
<asp:linkbutton id="cmdDel" runat="Server" CommandName="SelectDelete" </asp:linkbutton>

Now in your sub:
Sub DataGrid1_ItemCommand(ByVal s As Object, ByVal e As DataGridCommandEventArgs)
    Select Case e.CommandName
        Case "SelectDelete"
             'Delete the record code goes here (his Listing E)
    End Select
End Sub

It works great for me.  If the user clicks on "OK" of the confirm box it will call this sub.  If the user clicks on cancel, nothing should happen.  (This sub will NOT be called)
Hope this clarifys it.  
dwcorwith
0
 
LVL 2

Expert Comment

by:dwcorwith
Comment Utility
Oops I forgot, you will also need the following in the <asp:Datagrid > statement
<asp:DataGrid1  OnItemCommand="DataGrid1_ItemCommand"/>
0

Featured Post

6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

Join & Write a Comment

This article discusses the ASP.NET AJAX ModalPopupExtender control. In this article we will show how to use the ModalPopupExtender control, how to display/show/call the ASP.NET AJAX ModalPopupExtender control from javascript, how to show/display/cal…
IntroductionWhile developing web applications, a single page might contain many regions and each region might contain many number of controls with the capability to perform  postback. Many times you might need to perform some action on an ASP.NET po…
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, Just open a new email message.  In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

728 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

9 Experts available now in Live!

Get 1:1 Help Now