Solved

DataGrid Delete Popup Box asp.net (vb)

Posted on 2004-04-09
4
412 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Want Experts Exchange at your fingertips?

With Experts Exchange’s latest app release, you can now experience our most recent features, updates, and the same community interface while on-the-go. Download our latest app release at the Android or Apple stores today!

Question has a verified solution.

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

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 informatio…
I would like to start this tip/trick by saying Thank You, to all who said that this could not be done, as it forced me to make sure that it could be accomplished. :) To start, I want to make sure everyone understands the importance of utilizing p…
In this video we outline the Physical Segments view of NetCrunch network monitor. By following this brief how-to video, you will be able to learn how NetCrunch visualizes your network, how granular is the information collected, as well as where to f…
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …

631 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