We help IT Professionals succeed at work.

Check out our new AWS podcast with Certified Expert, Phil Phillips! Listen to "How to Execute a Seamless AWS Migration" on EE or on your favorite podcast platform. Listen Now

x

put validation on gridview cancel image button field

Medium Priority
679 Views
Last Modified: 2012-06-21
I have a need to put a validation on a gridview image button field.  They want the user to ok the delete.  Never done it on a gridview button control.  I am assuming you would do it in gridview row data event like in previous 1.1.  Here is what I tried but nothing seems to work for me.
Protected Sub myGridViewOut_RowDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewRowEventArgs) Handles myGridViewOut.RowDataBound

        Dim btnIssues As LinkButton
        Dim btnCheckout As LinkButton
        Dim Delete As ImageButton
        If (e.Row.RowType = DataControlRowType.DataRow) Then
            If e.Row.Cells(2).Text.Contains("NO") Or e.Row.Cells(3).Text.Contains("NO") Or e.Row.Cells(4).Text.Contains("NO") Then
                btnIssues = CType(e.Row.Cells(5).Controls(0), LinkButton)
                btnCheckout = CType(e.Row.Cells(6).Controls(0), LinkButton)
                btnIssues.Enabled = False
                btnCheckout.Enabled = False
            End If

            Delete.Attributes.Add(ScriptManager.RegisterClientScriptBlock(Page, GetType(Page), "OpenWindow", "NoIssues();", True))
        End If
    End Sub

Open in new window

Comment
Watch Question

Author

Commented:
All,

Tried this as well
  Delete.Attributes.Add("onclick", "javascript:return " + "confirm('Are you sure you want to delete this record')")

but then I get this error of object not set to an instance of an object.  I am assuming becuase it has no data.
CERTIFIED EXPERT
Most Valuable Expert 2012
Top Expert 2014
Commented:
Unlock this solution and get a sample of our free trial.
(No credit card required)
UNLOCK SOLUTION
Obadiah ChristopherDeveloper User Interface
CERTIFIED EXPERT

Commented:
I think u need to addif(e.Row.RowType == DataControlRowType.DataRow) { code for buton... }

Author

Commented:
CodeCruiser:

Ok got this method to work from one of the examples, but the result is that it now does not delete anything, it gives the confirmation, but then if I say ok, the row is not deleted.

Protected Sub myGridViewOut_RowDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewRowEventArgs) Handles myGridViewOut.RowDataBound

        Dim btnIssues As LinkButton
        Dim btnCheckout As LinkButton
        Dim Delete As ImageButton
        If (e.Row.RowType = DataControlRowType.DataRow) Then
            If e.Row.Cells(2).Text.Contains("NO") Or e.Row.Cells(3).Text.Contains("NO") Or e.Row.Cells(4).Text.Contains("NO") Then
                btnIssues = CType(e.Row.Cells(5).Controls(0), LinkButton)
                btnCheckout = CType(e.Row.Cells(6).Controls(0), LinkButton)
                btnIssues.Enabled = False
                btnCheckout.Enabled = False
            End If

            Delete = CType(e.Row.Cells(7).Controls(0), ImageButton)
            Delete.OnClientClick = String.Format("return confirm('Are you sure you want to delete')")
        End If
    End Sub




 If (e.CommandName = "Del") Then
            Dim Id As Integer = myGridViewOut.DataKeys(row).Values("intSRPAttendId").ToString
            Dim SSN As Integer = myGridViewOut.DataKeys(row).Values("strSSN").ToString

            sql = "Update tblSRPAttendance set bitActive = NULL, bitDental = NULL, bitMedical = NULL, bitAdmin = NULL, dtDentalLog = NULL, dtMedicalLog = NULL, dtAdminLog = NULL, bitCancel = 1 where " _
                & "intSRPAttendID = " & Id & ";Delete from tblSRPEventData where intPersonnelId = " & SSN

            insertUpdateDelete(sql)

            FillGridview()
        End If




 <asp:ButtonField ButtonType="Image" CommandName="Del" HeaderText="Delete" ImageUrl="~/Images/Delete Circle Small.png"  />

CERTIFIED EXPERT
Most Valuable Expert 2012
Top Expert 2014

Commented:
This may not make a difference but you are missing a ; in javascript

Delete.OnClientClick = String.Format("return confirm('Are you sure you want to delete');")

Author

Commented:
Ok,
masde the switch, but it still does not delete if I click ok.  I am wondering if I need to trap the reutn event and then delete from here??

Author

Commented:
Would update panels mess with any of this so that it did not return correctly??

Author

Commented:
Thanks, i will ask another question of why mine does not work.
CERTIFIED EXPERT
Most Valuable Expert 2012
Top Expert 2014

Commented:
Are you handling the RowCommand event?
Unlock the solution to this question.
Thanks for using Experts Exchange.

Please provide your email to receive a sample view!

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.