Delete Confirm not Deleting

I followed the instruction in this tutorial (http://asp.net/learn/dataaccess/tutorial22vb.aspx) to add delete confirm to a GridView's FieldCommand Delete button.  It will delete the record if I comment out this code but not if I don't.  I get the confirm dialog and a postback but the record is not deleted.  DataKeyNames are set.  What's the deal?

Here's the code.
Protected Sub GridView1_RowDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewRowEventArgs)

        'Delete Confirm

        If e.Row.RowState = DataControlRowState.Normal Then

            If e.Row.RowType = DataControlRowType.DataRow Then

                Dim db As ImageButton = CType(e.Row.Cells(0).Controls(2), ImageButton)

                Dim record As DAL.CustomersDataSet.CustomersRow = CType(CType(e.Row.DataItem, System.Data.DataRowView).Row, DAL.CustomersDataSet.CustomersRow)

                db.OnClientClick = String.Format("return confirm('Are you certain you want to delete the {0} customer?');", record.CustomerName.Replace("'", "\'"))

            End If

        End If

      End Sub

 

and the GridView

    <asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" DataKeyNames="CustomerID"

        DataSourceID="ObjectDataSource1" OnRowUpdated="GridView1_RowUpdated" OnRowUpdating="GridView1_RowUpdating" OnRowDataBound="GridView1_RowDataBound" OnRowDeleted="GridView1_RowDeleted">

        <Columns>

            <asp:CommandField ShowDeleteButton="True" ShowEditButton="True" ButtonType="Image" CancelImageUrl="~/Images/Cancel.gif" DeleteImageUrl="~/Images/Delete.gif" EditImageUrl="~/Images/Edit.gif" UpdateImageUrl="~/Images/Save.gif" />

            <asp:BoundField DataField="CustomerID" HeaderText="CustomerID" InsertVisible="False"

                ReadOnly="True" SortExpression="CustomerID" Visible="False" />

            <asp:BoundField DataField="CustomerName" HeaderText="Customer Name" SortExpression="CustomerName" />

            <asp:TemplateField HeaderText="Jobs">

                <ItemTemplate>

                    <asp:LinkButton ID="ViewJobsLinkButton" runat="server" CommandArgument='<%# Eval("CustomerID") %>' Text='<%# Eval("CountOfJobs") %>' OnClick="ViewJobsLinkButton_Click"></asp:LinkButton>

                </ItemTemplate>

                <ItemStyle HorizontalAlign="Center" />

            </asp:TemplateField>

            <asp:TemplateField HeaderText="File Directory">

                <ItemTemplate>

                    <asp:HyperLink ID="CustomerDirectoryHyperLink" runat="server" ImageUrl="~/Images/Folder.JPG"></asp:HyperLink>

                </ItemTemplate>

                <ItemStyle HorizontalAlign="Center" />

            </asp:TemplateField>

        </Columns>

        <EmptyDataTemplate>

            <strong><span style="color: red">No records returned!</span></strong>

        </EmptyDataTemplate>

    </asp:GridView>

0
mtsonic
11/7/2006 3:30:30 AM
asp.net.web-forms 93655 articles. 6 followers. Follow

7 Replies
1237 Views

Similar Articles

[PageSpeed] 45

There is no delete operation in your code and only delete confirm here.Try to add delete code according to CustomerID in GridView_RowCommand event handler.Try to refer to the following links which have a confirm delete in GridView.

http://www.codeproject.com/aspnet/GridViewConfirmDelete.asp

http://pluralsight.com/blogs/fritz/archive/2006/03/22/20514.aspx

0
Jasson_king
11/7/2006 7:10:27 AM
Thanks for the reply.  I assumed that if the confirm function returned true that it continued with the Delete command associated with the delete button.  I thought it would still be associated because the field is still a CommandField.  I guess the OnClientClick bypasses the association to the delete method.  In the first link you posted the delete command is 'DeleteRecordByID(categoryID);'.  I am using concurrency and need to include some business logic.  Does this mean that I would have to reference all of the Delete method's fields in Code-Behind so I can use the BLL's Delete method or is there a way to still use the GridView's or ObjectDataSource's Delete method?
0
mtsonic
11/7/2006 1:33:44 PM

Hi,

   You can still use the delete method in BLL through ObjectDataSource.Here are some sample codes to comfirm deleting a record in GridView for your reference.

     <asp:CommandField HeaderText="Command" ShowDeleteButton="True"
                ShowEditButton="True" DeleteText="&lt;span onclick=&quot;return confirm('Are you sure to delete?');&quot;&gt;Delete&lt;/span&gt;">
                <ItemStyle Width="135px" />
     </asp:CommandField>


 Wish this can give you some help.

0
Jasson_King
11/8/2006 1:50:32 AM

Can you explain this?

="&lt;span onclick=&quot;return confirm('Are you sure to delete?');&quot;&gt;Delete&lt;/span&gt;">

It gives me errors.  I'm assuming it's suppose to followup with the Delete method if confirm returns true which is exactly what I am looking for but I don't understand the syntax.

0
mtsonic
12/1/2006 4:37:53 PM

I probably should mention that my TableAdapters in the DAL support concurancy.  This means that if I can't use the Delete method of the object data source and would have to set the parameters in code I would have to set every original value parameter.  This seams overkill just to get a delete confirm.

I also understand that I can convert the field to a template field (which is how I accomplished this with GridViews) but with DetailsViews this makes the CommandField look like a DataField which is undesirable.  Yes, I could format it but then aren't we getting too far away from GUI to achieve something that is typical !?

0
mtsonic
12/1/2006 4:57:18 PM

Hi,

   The special characters are not nessary and you can remove them in your codes.Just as the following, that's right. Maybe this is my mistake.

     <asp:CommandField HeaderText="Command" ShowDeleteButton="True" ShowEditButton="True" DeleteText="onclick=return confirm('Are you sure to delete?');">
           <ItemStyle Width="135px" />
     </asp:CommandField>

Wish this can help you.

0
Jasson_King
12/4/2006 4:17:50 AM

If there is concurrency in your TableAdapters in the DAL,you can still use ObjectDataSource and only need to pass some parameters to the DAL.Here some sample codes which are similiar to this for reference.

  protected void btn_Report_Click(object sender, EventArgs e)
    {
        ForumsUserStatBLL fub = new ForumsUserStatBLL();
        IDataReader rd = fub.GetRecord(Performancing.Manager.UserID, date_Picker.SelectedDate);
        if (rd.Read())
        {
            lb_DuplicateReport.Text = "Error: You've already reported for selected date!";
        }
        else
        {
            fub.CreateRecord(Performancing.Manager.UserID, int.Parse(tb_Answered.Text), decimal.Parse(tb_WorkHour.Text), date_Picker.SelectedDate, tb_Comment.Text);                           //Pass parameters to DAL which is used to ObjectDataSource
            lb_DuplicateReport.Text = "Hey~ Well done! Keep up the good working.";
            gv_MyRecent.DataBind();
        }
        rd.Close();
    } 

Wish this can helps you.

0
Jasson_King
12/4/2006 4:27:24 AM
Reply:

Similar Artilces:

Deletes are not being deleted.
Using ASA 7.03 I am having a problem in deleting field service orders that have been completed. Just getting started with sync so I am probably making a dumb mistake or just leaving out a step. The download_delete_cursor script is: Select ordernumber from ServiceOrderEntryMaster where Tech = ? and Order_Complete = 'Y' This based on the verbose reply from the MobiLink Synchronization server is picking the correct work order ( number 326 ) and showing a Delete Row line in the log. But the work order is not being deleted on the remote side. What could I be doing wron...

add/change name/delete server files via vb.net web form
I have the add(upload) part of this page figured out. I have an application with an "Images" sub directory. I know how to access the getfiles() method from the system.IO namespace. I am using a while loop to create a table with an edit button (so that you can change the name of the file) and a delete button so you can remove the file from the server. Each file is on a new line much like it would look if it was bound to a datalist or datagrid. Here is where I am clueless. Can anyone point me in the right direction? I am not looking for someone to write this for me, beca...

Ask User to confirm delete before deleting
Hi Guys Using vb.net sql2005 and .net2.0 I have a detailsview which allows the user to delete, i want to pop up a window asking Are You Sure, Yes No, and if they select yes it will perform the delete or if they select no it will cancel the deletion.I do not want to use JAVASCRIPT I have heard of a ASP.net Message box but have never used it can i use this? if so can someone provide an example, tutorial or solutionThanks and Kind RegardsNo one said it was gonna be easy, then again, nothing worth doing ever is. teddymeu4u:I have heard of a ASP.net Message box but have never used it can i ...

Need a delete confirmation when i delete a record in a datagrid
Hi there, I am using RowSelectorColumn in my datagrid. By checking the radio button and clicking on the delete button at the bottom of the page it deletes the record. Deleting the record is working fine. But i need a javascript confirmation before it deletes the record. i have seen many a examples on interenet which has the deleting functionality handeled differently. All examples contain delete buttons in the grid itself using ItemDataBound. But mine is different. In the btnDelete_click i am trying to find the name of the control on the form and add a javascript function to it. But ...

help!! Cancel Confirm Delete still deletes!
i've been searching for an answer for this, and cant seem to find one.  i have a datagrid, with a confirm delete.  the message box pops up fine.   if i click delete, the record gets deleted.  when i click cancel, it STILL gets deleted! :-(   i'm going nuts.  i hope someone can help.   heres some code, and i'm using a buttoncolumn so you know: Private Sub DataGrid_ItemDataBound(ByVal s As Object, ByVal e As DataGridItemEventArgs) Handles dgJobs.ItemDataBound Dim itemType as ListItemType = e.Item.ItemType If (itemType = ListItemType.Item Or ...

Delete Confirmation for Delete Command Field in gridview
Hi, I have 2 command fields (Edit and Delete) under Column 4 of my gridview.  I have not been able to figure out how to set the Delete Confirmation just for the Delete command.  Ironically, I know how to to that if they were in 2 separate columns (Edit in Column 4, Delete in Column 5).  Unfortunately, the requirement asking to have both of these commands under a single column (Edit Delete in Column 4).  How do you accomplish this if both Edit and Delete are in the same column?   This is the code that I used to set the delete confirmation if the DELETE COMM...

superreview requested: [Bug 198939] There are no confirmation on address card deletion : [Attachment 170491] Add prompt for confirm card deletion
Mark Banner <mark@standard8.demon.co.uk> has asked Scott MacGregor <mscott@mozilla.org> for superreview: Bug 198939: There are no confirmation on address card deletion https://bugzilla.mozilla.org/show_bug.cgi?id=198939 Attachment 170491: Add prompt for confirm card deletion https://bugzilla.mozilla.org/attachment.cgi?id=170491&action=edit ...

superreview denied: [Bug 198939] There are no confirmation on address card deletion : [Attachment 170491] Add prompt for confirm card deletion
Scott MacGregor <mscott@mozilla.org> has denied Mark Banner <mark@standard8.demon.co.uk>'s request for superreview: Bug 198939: There are no confirmation on address card deletion https://bugzilla.mozilla.org/show_bug.cgi?id=198939 Attachment 170491: Add prompt for confirm card deletion https://bugzilla.mozilla.org/attachment.cgi?id=170491&action=edit ...

Having a delete confirmation box appear when a record is deleted from a gridview.
Hello i have a page with a gridview component that manipluates data from a SQL Server database. I have enabled deleting on the gridview, which automatically has coded my delete function. however i would like when the user clicks delete, a dialog box appear confirming if they wish to delete the record and presented with the options ok or cancel. Is there a way of implementing this? Any help would be appreciated. Thanks, James In GridView Tasks, select Edit Columns... Select the Delete command and then click the link "Convert this field into a template" In the asp source code, ...

delete vs []delete
Hi all, I have some strange behavior in some code and I did see that I had delete when I should have []delete; Now I am not questioning the validity of []delete for an array of items as opposed to delete for a singularity. My question what kind of behavior would you expect if you mismatch new / delete as I described. Colin. On Thu, 5 Feb 2009 05:23:50 -0800 Colin Maharaj <noreply@nohost.com> wrote: > My question what kind of behavior would you expect > if you mismatch new / delete as I described. I wouldn't expect /anything/, it's undefined. -- ...

Gridview Delete not Deleting
I am trying to use a command button to delete a row from a gridview. When I click the command button though, the page posts but my record is still there... no errors, just nothing seems to happen. Below is what I think is the relevant code, let me know if you need to see anything else.  I'm kinda new to working with gridview objects, it would be nice if I could see what SQL command is acctually ran... maybe there are other things I can check too, I'm just not sure how.   <asp:GridView ID="GridView1" runat="server" AllowSorting="True"&nbs...

Deleted items not deleting
We are running GW 7.0.1 W2K3 server agents and 7.0.1 workstation clients. Some users have thousands of items in their trash and other folders within their account. The problem is when you select all the messages and delete them, they don't actually delete. They stay in the users client. An expire/reduce doesn't do anything either. We also tried setting up in consoleone under groupwise>client>environment>cleanup -- the clients to automatically delete items and that didnt' work either. Does anyone have any suggestions??? Will, i will try to run a GW check...

insertion/deletion on same web form
i want making a module for adding, inserting and deleting new supplier. now i want all this one one screen. i mean the list of all suppliers would be displayed and there would be options for insertion and deletion. if we want to delete a supplier already present in the database then by selecting that supplier; it should be deletedsimilarly insertion should be on same page and there are two field for this i.e. supplier id and supplier name can u plz help me in doing so? i'm using .NET 1.1 Why not just list them in a datagrid and put some fields and an 'insert' button above the datagrid lik...

how to implement client side delete confirmation before deleting any data
Hey Guys!  I am wondering how to implement the client side delete confirmation message box using javascript. I have to implement in such a way that when i select a delete linkbutton from datagrid, it should display a confirmation message box, 'Are you sure to delete?', If i clicked on OK button than delete that row else do nothing. Here is my code: aspx page: <asp:DataGrid Runat="server" ID="datagrid" ShowHeader="True" AutoGenerateColumns="False" PageSize="20" AllowPaging="True" OnDeleteCommand=&...

Web resources about - Delete Confirm not Deleting - asp.net.web-forms

Deleting Online Predators Act of 2006 - Wikipedia, the free encyclopedia
( DOPA ) is a bill ( H.R. 5319 ) brought before the United States House of Representatives on May 9, 2006 by Republican Pennsylvania Representative ...

Are You Deleting Facebook Messages Or Unknowingly Saving Them?
You might find yourself, on occasion, the recipient or sender of hostile or just plain weird Facebook messages . And you likely delete these ...

Deleting your Facebook page is foolish
... brag, trailing closely behind that fantastically annoying “I don’t even have a TV , never mind watch the drivel!” Let’s lay it out: deleting ...

AdWords Campaign Experiments: Applying or deleting your experimental changes - YouTube
To improve your AdWords experience, we're testing a new tool that helps you optimize your account. AdWords Campaign Experiments, or ACE, does ...

Deleting abusive online content a 'near impossible' task
POSTING offensive, harassing, intimidating or defamatory content online takes mere seconds, but getting it removed can take what feels like a ...

Paleo advocate Pete Evans accused of deleting critical posts on Facebook
Is Paleo Pete Evans is open to dietary debate? Some say he's not.

Microsoft on the threshold of deleting 'appalling' Windows 8 software
MICROSOFT plans to cut its losses on Windows 8, the latest version of the software that runs the majority of the world's computers, jettisoning ...

How to get iOS 8 without deleting everything on your phone
If you've tried downloading iOS 8, or know anyone who has already done so, you're probably familiar with the biggest complaint: The download ...

Deleting gun data breaks law, info czar says
Information Commissioner Suzanne Legault told a Commons committee Tuesday that a federal bill to destroy all the records in the long-gun registry ...

Jason Kenney under fire for praising ‘perfect, unaccented English’, deleting tweet
Canada's Minister for Multiculturalism, Jason Kenney, caused an upset Monday after praising an 11-year-old Iraqi refugee who "already speaks ...

Resources last updated: 1/21/2016 10:03:36 AM