Solved

problem with deleting a row from datagrid after confirmation

Posted on 2004-10-19
7
601 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

One of the pain points with developing AJAX, JavaScript, JQuery, and other client-side behaviors is that JavaScript doesn’t allow for cross domain request for pulling content. For example, JavaScript code on www.johnchapman.name could not pull conte…
In .NET 2.0, Microsoft introduced the Web Site.  This was the default way to create a web Project in Visual Studio 2005.  In Visual Studio 2008, the Web Application has been restored as the default web Project in Visual Studio/.NET 3.x The Web Si…
I've attached the XLSM Excel spreadsheet I used in the video and also text files containing the macros used below. https://filedb.experts-exchange.com/incoming/2017/03_w12/1151775/Permutations.txt https://filedb.experts-exchange.com/incoming/201…

710 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