Protected Sub GridView1_RowDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewRowEventArgs)
Handles GridView1.RowDataBound
If (e.Row.RowType = DataControlRowType.DataRow) Then
e.Row.Cells(0).Attributes.Add("onclick", "alert('delklick')")
End If
End Sub
då kommer man ju åt alla knappar i första kolumnen...kan man sedan urskilja delete-knappen?
Protected Sub GridView1_RowDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewRowEventArgs)
Handles GridView1.RowDataBound
If e.Row.RowType = DataControlRowType.DataRow Then
Dim myTableCell As TableCell
myTableCell = e.Row.Cells(0)
Dim myDeleteButton As ImageButton
myDeleteButton = myTableCell.Controls(2)
myDeleteButton.Attributes.Add("onclick", "alert('delklick')")
End If
End Sub
Protected Sub GridView1_RowDataBound(ByVal sender As Object, ByVal e As GridViewRowEventArgs)
Handles GridView1.RowDataBound
If (e.Row.RowType = DataControlRowType.DataRow) Then
CType(e.Row.Cells(0).Controls(2), ImageButton).OnClientClick = "alert('delklick')"
End If
End Sub
Mycket bättre, på rätt knapp..och endast rätt knapp, det görs en postback, men raderar inte raden...varför?
Protected Sub GridView1_RowDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewRowEventArgs)
Handles GridView1.RowDataBound
Dim row As GridViewRow = e.Row
If row.RowType = DataControlRowType.DataRow Then
Dim cell As TableCell = e.Row.Cells(0)
For Each ctl As Control In cell.Controls
If TypeOf ctl Is ImageButton Then
Dim link As ImageButton = CType(ctl, ImageButton)
If link.CommandName = "Delete" Then
link.ToolTip = "Radera"
link.Attributes("onclick") = "javascript:return " & _
"confirm('Are you sure you want to delete the selected record?')"
End If
End If
Next
End If
End Sub
Protected Sub GridView1_RowDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewRowEventArgs)
Handles GridView1.RowDataBound
Dim row As GridViewRow = e.Row
If row.RowType = DataControlRowType.DataRow Then
Dim cell As TableCell = e.Row.Cells(0)
For Each ctl As Control In cell.Controls
If TypeOf ctl Is ImageButton Then
Dim link As ImageButton = CType(ctl, ImageButton)
If link.CommandName = "Delete" Then
link.ToolTip = "Radera"
link.Attributes("onclick") = "if(confirm('Vill du verkligen radera...?')){" +
ClientScript.GetPostBackEventReference(link, "") & "}else{return false;}"
End If
End If
Next
End If
End Sub
139 ms totalt · 3 externa anrop · v20260731065814-full.25f56b17