, 당신은 솔루션 탐색기 탭 (내가 VWD를 사용)에서 루트 파일에 rightclicking하여 된 .vb 파일/클래스를 만들어야합니다. 새로 추가를 선택하고 클래스 페이지를 선택하십시오. 공유 클래스가 상주 할 App_Code 폴더를 만들 것을 제안합니다. 파일/클래스 이름을 "DeleteButtonField.vb"로 지정하고 확인을 클릭하십시오.
그런 다음 DeleteButtonField라는 새 .vb 파일을 열고 다음 코드를 복사하여 붙여 넣거나 입력 할 수 있습니다.()는 재정의 하위 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>
당신은 또한 <퍼센트의 @ 페이지 후 페이지 상단에 한 줄을 추가해야
...>로 다음은
<%@ Register TagPrefix="custom" Namespace="myControls" %>
GridView의 새로운 삭제 버튼을 사용하려는 모든 페이지에 추가해야합니다.이 설정을 web.config의 기본값으로 설정할 수있는 방법이있을 수 있습니다. 내 학습의이 단계에서.
.aspx 페이지를 저장하고 테스트하십시오.이제 응용 프로그램의 모든 GridView에 연결할 수있는 공통적 인 Sub (표준 삭제 버튼과 그 동작을 정의)를 정의했습니다.
@abatishchev 바로 다음 작업을 수행 했습니까? – Kelsey
아니요, 포기했습니다. 내 맞춤 삭제 버튼은 항상 하드 코딩 된 영어 라벨과 동일합니다. – abatishchev