Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

DataGrid Delete Popup Box asp.net (vb)

Posted on 2004-04-09
4
Medium Priority
?
421 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 200 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

Independent Software Vendors: 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

Have you ever needed to get an ASP script to wait for a while? I have, just to let something else happen. Or in my case, to allow other stuff to happen while I was murdering my MySQL database with an update. The Original Issue This was written…
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…
this video summaries big data hadoop online training demo (http://onlineitguru.com/big-data-hadoop-online-training-placement.html) , and covers basics in big data hadoop .
When cloud platforms entered the scene, users and companies jumped on board to take advantage of the many benefits, like the ability to work and connect with company information from various locations. What many didn't foresee was the increased risk…

927 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