Solved

problem with deleting a row from datagrid after confirmation

Posted on 2004-10-19
7
599 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
ID: 12355606
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
ID: 12355608
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
ID: 12357827
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
ID: 12380737
Oops I forgot, you will also need the following in the <asp:Datagrid > statement
<asp:DataGrid1  OnItemCommand="DataGrid1_ItemCommand"/>
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I recently went through the process of creating a Calendar Control of events with the basis of using a database to keep track of the dates that are selectable, one requirement was to have the selected date pop-up in a simple lightbox.  At first this…
In an ASP.NET application, I faced some technical problems. In this article, I list them out and show the solutions that I found.  I hope it will be useful. Problem: After closing a pop-up window, the parent page should be refreshed automaticall…
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

685 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