[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 651
  • Last Modified:

put validation on gridview cancel image button field

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

0
kdeutsch
Asked:
kdeutsch
  • 5
  • 3
1 Solution
 
kdeutschAuthor 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.
0
 
informaniacCommented:
I think u need to addif(e.Row.RowType == DataControlRowType.DataRow) { code for buton... }
0
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
kdeutschAuthor 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"  />

0
 
CodeCruiserCommented:
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');")
0
 
kdeutschAuthor 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??
0
 
kdeutschAuthor Commented:
Would update panels mess with any of this so that it did not return correctly??
0
 
kdeutschAuthor Commented:
Thanks, i will ask another question of why mine does not work.
0
 
CodeCruiserCommented:
Are you handling the RowCommand event?
0

Featured Post

 [eBook] Windows Nano Server

Download this FREE eBook and learn all you need to get started with Windows Nano Server, including deployment options, remote management
and troubleshooting tips and tricks

  • 5
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now