Solved

DataGrid Delete Popup Box asp.net (vb)

Posted on 2004-04-09
4
381 Views
Last Modified: 2012-05-04
SEE HOW DO I MAKE THIS WORK.....
When I click on the "Delete" Button, I am wanting a javascript confirm box to appear.  I want to create this script in the code behind and not in the HTML portion.  Any suggestions for the "onclick" attributes to a datagrid button?

'HERE IS MY DELETE BUTTON in HTML Code
<asp:ButtonColumn Text="Delete" ButtonType="PushButton" CommandName="Delete"></asp:ButtonColumn>


'DATAGRID
 Sub dgLinks_Click(ByVal source As System.Object, ByVal e As System.Web.UI.WebControls.DataGridCommandEventArgs) Handles dgLinks.ItemCommand
        If e.CommandName = "Edit" Then
            pnlEdit.Visible = True
           
        ElseIf e.CommandName = "Delete" Then
*******HOW DO I MAKE THIS WORK     ***********************
 
      btn.attributes.Add("onclick", "javascript: return confirm('Are you sure you want to remove this item?');")

***********************************************************************
            Dim objDeleteData As New clDeleteData
            Try
                'Delete News Events
                objDeleteData.DeleteApp(CType(dgLinks.DataKeys(e.Item.ItemIndex), Integer))
                'redirect back to the page
                'Response.Redirect("menu.aspx")
            Catch ex As Exception
                Throw New Exception(ex.Message)
            Finally
                objDeleteData = Nothing
            End Try
        End If
    End Sub
0
Comment
Question by:luckyinc
  • 2
  • 2
4 Comments
 
LVL 7

Accepted Solution

by:
ramesh12 earned 50 total points
ID: 10792332
0
 
LVL 7

Expert Comment

by:ramesh12
ID: 10792344
Goes somethig like this

Sub DataGrid_ItemCreated(Sender As Object, e As DataGridItemEventArgs)
        Select Case e.Item.ItemType
          Case ListItemType.Item, ListItemType.AlternatingItem, ListItemType.EditItem
            Dim myDeleteButton As Button
            myDeleteButton = e.Item.FindControl("btnDelete")
             myDeleteButton.Attributes.Add("onclick",_
                  "return confirm('Are you sure you want to delete this company?');")  ------

        End Select
    End Sub
0
 

Author Comment

by:luckyinc
ID: 10793108
When I tried the ItemCreated command, it did not prompt for the confirm box
0
 

Author Comment

by:luckyinc
ID: 10793284
Is there a way where I could make it work within my datagrid_click event within this ElseIf statement?

 ElseIf e.CommandName = "Delete" Then

            Dim objDeleteData As New clDeleteData
            Try
                'Delete News Events
                objDeleteData.DeleteApp(CType(dgLinks.DataKeys(e.Item.ItemIndex), Integer))
                'redirect back to the page
                'Response.Redirect("menu.aspx")
            Catch ex As Exception
                Throw New Exception(ex.Message)
            Finally
                objDeleteData = Nothing
            End Try
        End If
    End Sub
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Classic ASP migration directions 7 67
Issue with Loop 4 50
Summernote required 3 102
JQuery to parse xml string and get element by id 4 23
I have helped a lot of people on EE with their coding sources and have enjoyed near about every minute of it. Sometimes it can get a little tedious but it is always a challenge and the one thing that I always say is:  The Exchange of information …
I was asked about the differences between classic ASP and ASP.NET, so let me put them down here, for reference: Let's make the introductions... Classic ASP was launched by Microsoft in 1998 and dynamically generate web pages upon user interact…
In this video I am going to show you how to back up and restore Office 365 mailboxes using CodeTwo Backup for Office 365. Learn more about the tool used in this video here: http://www.codetwo.com/backup-for-office-365/ (http://www.codetwo.com/ba…
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…

867 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

16 Experts available now in Live!

Get 1:1 Help Now