Solved

DataGrid Delete Popup Box asp.net (vb)

Posted on 2004-04-09
4
370 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
Comment Utility
0
 
LVL 7

Expert Comment

by:ramesh12
Comment Utility
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
Comment Utility
When I tried the ItemCreated command, it did not prompt for the confirm box
0
 

Author Comment

by:luckyinc
Comment Utility
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

What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

Join & Write a Comment

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 demonstration started out as a follow up to some recently posted questions on the subject of logging in: http://www.experts-exchange.com/Programming/Languages/Scripting/JavaScript/Q_28634665.html and http://www.experts-exchange.com/Programming/…
This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're looking for how to monitor bandwidth using netflow or packet s…
This video explains how to create simple products associated to Magento configurable product and offers fast way of their generation with Store Manager for Magento tool.

772 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

10 Experts available now in Live!

Get 1:1 Help Now