.vb/class, " " ( VWD). " " "". App_Code, . / "DeleteButtonField.vb" "".
.vb DeleteButtonField, . ( , Intellisense , Sub InitializeCell (........).)
Imports Microsoft.VisualBasic
Imports System
Imports System.Web.UI.WebControls
Namespace myControls
Public Class DeleteButtonField
Inherits ButtonField
Private _confirmText As String = "Delete This Record?"
Public Property ConfirmText() As String
Get
Return _confirmText
End Get
Set(ByVal value As String)
_confirmText = value
End Set
End Property
Public Sub New()
Me.CommandName = "Delete"
Me.Text = "Delete"
End Sub
Public Overrides Sub InitializeCell(ByVal cell As System.Web.UI.WebControls.DataControlFieldCell, ByVal cellType As System.Web.UI.WebControl.DataControlCellType, ByVal rowState As System.Web.UI.WebControl.DataControlRowState, ByVal rowIndex As Integer)
MyBase.InitializeCell(cell, cellType, rowState, rowIndex)
If cellType = DataControlCellType.DataCell Then
Dim button As WebControl = CType(cell.Controls(0), WebControl)
button.Attributes("onclick") = String.Format("return confirm('{0}');", _confirmText)
End If
End Sub
End Class
End Namespace
.vb. .aspx GridView (.. ). , , "" , . , ,
<custom:DeleteButtonField ConfirmText="Are you sure that you want to delete this record?"></custom:DeleteButtonField>
<% @Page... >
<%@ Register TagPrefix="custom" Namespace="myControls" %>
, "" GridView. web.config; .
Save the .aspx page and check. Now you have defined a common Sub (which defines the standard Delete button and its behavior), which you can connect to any GridView in your application.
source
share