This is the way I handle deletes...You must know when to process the events
that are triggered.

 

On the ItemDataBound run a routine to bind code similar to this to the
datagrid.

 

Public Sub dgresults_ItemDataBound(ByVal Sender As Object, ByVal e As
System.Web.UI.WebControls.DataGridItemEventArgs)

 

        If e.Item.ItemType <> ListItemType.Header And e.Item.ItemType <>
ListItemType.Footer Then

            Dim Deletebutton As LinkButton = e.Item.Cells(0).Controls(0)

            Deletebutton.Attributes("onclick") = "javascript:return
confirm('Are you sure you want to delete Employee " & _

                DataBinder.Eval(e.Item.DataItem, "Emp_No") & "?')"

        End If

    End Sub

 

Then, if the users selects OK the OnDelete Event is triggered and I set a
subroutine similar to this:

 

Public Sub dgResults_Delete(ByVal Sender As Object, ByVal e As
System.Web.UI.WebControls.DataGridCommandEventArgs) Handles
dgResults.DeleteCommand

        Dim index As Integer

        index = dgResults.DataKeys(e.Item.ItemIndex)

        ' Add code to delete data from data source

 

        Dim sqlstr As String = "DELETE FROM Employee " & _

            "WHERE Emp_No = " & index & ""

        Dim DeleteCommand As New SqlCommand(sqlstr, aConnection)

        aConnection.Open()

        DeleteCommand.ExecuteNonQuery()

 

        dgResults.DataBind()

    End Sub

 

--Eric 

 

-----Original Message-----
From: Greg Ewing [mailto:[EMAIL PROTECTED] 
Sent: Tuesday, September 14, 2004 4:38 PM
To: [EMAIL PROTECTED]
Subject: RE: [AspNetAnyQuestionIsOk] How to Confirm a Delete in an ASP.NET
Datagrid

 

No, if the person clicks yes the Button Click event will be sent to the
server where you will need to process it and delete the record.  If they
click cancel the click event will be cancelled and the user will stay on the
current page.

Greg Ewing [MVP]
www.citidc.com 

----------------------------------------
From: Anna Leon <[EMAIL PROTECTED]>
Sent: Tuesday, September 14, 2004 1:29 PM
To: [EMAIL PROTECTED]
Subject: RE: [AspNetAnyQuestionIsOk] How to Confirm a Delete in an ASP.NET
Datagrid 

After hitting yes, will the record be deleted then?

--- [EMAIL PROTECTED] wrote:

> Add this line of code after Page_Load sub in your
> code behind, assuming that you named your delete
> button "btnDelete".
> 
> btnDelete.Attributes.Add("onclick",
> "javascript:if(confirm('Are you sure you want to
> delete this item?')== false) return false;")
> 
> 
> 
> 
> _____ 
> 
> 
> Zehra Altug | Intranet Applications Developer |
> Information Technology Group | Media General, Inc. |
> Tel: (804) 649-6149
> 
> 
> 
> -----Original Message-----
> From: sas0riza [ mailto:[EMAIL PROTECTED]
> Sent: Tuesday, September 14, 2004 4:02 PM
> To: [EMAIL PROTECTED]
> Subject: [AspNetAnyQuestionIsOk] How to Confirm a
> Delete in an ASP.NET
> Datagrid
> 
> 
> I would like to delete a record, but only after
> confirmation.
> 
> I have this JS function:
> 
> 
> function confirm_delete()
> {
> if (confirm("Are you sure you want to delete this
> item?")==true)
> return true;
> else
> return false;
> }
>  
> 
> 
> How do I incorporate it into my code?
> 
> 
> 
> 
> 
> 
> Yahoo! Groups Links
> 
> 
> 
> 
> 
> 
> 
> 
> 
> [Non-text portions of this message have been
> removed]
> 
> 

__________________________________________________
Do You Yahoo!?
Tired of spam? Yahoo! Mail has the best spam protection around 
http://mail.yahoo.com <http://mail.yahoo.com>  


Yahoo! Groups Links





[Non-text portions of this message have been removed]






Yahoo! Groups Sponsor



ADVERTISEMENT
 
<http://us.ard.yahoo.com/SIG=129r0a6t6/M=298184.5285298.6392945.3001176/D=gr
oups/S=1705006764:HM/EXP=1095280706/A=2352667/R=0/SIG=11t4iivpf/*http:/www.n
etflix.com/Default?mqso=60185359&partid=5285298> click here


 
<http://us.adserver.yahoo.com/l?M=298184.5285298.6392945.3001176/D=groups/S=
:HM/A=2352667/rand=868985580> 

 

  _____  

Yahoo! Groups Links

*         To visit your group on the web, go to:
http://groups.yahoo.com/group/AspNetAnyQuestionIsOk/
<http://groups.yahoo.com/group/AspNetAnyQuestionIsOk/> 
  

*         To unsubscribe from this group, send an email to:
[EMAIL PROTECTED]
<mailto:[EMAIL PROTECTED]
e> 
  

*         Your use of Yahoo! Groups is subject to the Yahoo! Terms of
Service <http://docs.yahoo.com/info/terms/> . 



[Non-text portions of this message have been removed]



------------------------ Yahoo! Groups Sponsor --------------------~--> 
Make a clean sweep of pop-up ads. Yahoo! Companion Toolbar.
Now with Pop-Up Blocker. Get it for free!
http://us.click.yahoo.com/L5YrjA/eSIIAA/yQLSAA/saFolB/TM
--------------------------------------------------------------------~-> 

 
Yahoo! Groups Links

<*> To visit your group on the web, go to:
    http://groups.yahoo.com/group/AspNetAnyQuestionIsOk/

<*> To unsubscribe from this group, send an email to:
    [EMAIL PROTECTED]

<*> Your use of Yahoo! Groups is subject to:
    http://docs.yahoo.com/info/terms/
 

Reply via email to