代码如下:
Imports Microsoft.VisualBasic
Imports System.Web
Imports System.Web.UI
Imports System.Web.UI.WebControls
Imports System.ComponentModel
Partial Class bulkedit
Inherits System.Web.UI.WebControls.GridView
Protected Overrides Function CreateRow(ByVal rowIndex As Integer, ByVal dataSourceIndex As Integer, ByVal rowType As System.Web.UI.WebControls.DataControlRowType, ByVal rowState As System.Web.UI.WebControls.DataControlRowState) As System.Web.UI.WebControls.GridViewRow
Return MyBase.CreateRow(rowIndex, dataSourceIndex, rowType, DataControlRowState.Edit)
End Function
<IDReferenceProperty(GetType(Control))> _
Public Property SaveButtonID() As String
Get
Dim val As String = Me.ViewState("SaveButtonID"

If val = Nothing Then
Return String.Empty
Else
Return val
End If
End Get
Set(ByVal value As String)
Me.ViewState("SaveButtonID"

= value
End Set
End Property
Protected Overrides Sub OnLoad(ByVal e As System.EventArgs)
MyBase.OnLoad(e)
If Me.SaveButtonID.ToString <> String.Empty Then
Dim btn As Control = RecursiveFindControl(Me.NamingContainer, Me.SaveButtonID)
If btn IsNot Nothing Then
If TypeOf (btn) Is Button Then
AddHandler CType(btn, Button).Click, AddressOf SaveClicked
ElseIf TypeOf (btn) Is LinkButton Then
AddHandler CType(btn, LinkButton).Click, AddressOf SaveClicked
ElseIf TypeOf (btn) Is ImageButton Then
'AddHandler CType(btn, ImageButton).Click, AddressOf SaveClicked
End If
End If
End If
End Sub
Protected Overrides Sub InitializeRow(ByVal row As System.Web.UI.WebControls.GridViewRow, ByVal fields() As System.Web.UI.WebControls.DataControlField)
MyBase.InitializeRow(row, fields)
For Each cell As DataControlFieldCell In row.Cells
If cell.Controls.Count > 0 Then
AddChangeHandler(cell.Controls)
End If
Next
End Sub
Private Sub AddChangeHandler(ByVal controls As ControlCollection)
For Each ctrl As Control In controls
If TypeOf (ctrl) Is TextBox Then
AddHandler CType(ctrl, TextBox).TextChanged, AddressOf handleRowChanged
ElseIf TypeOf (ctrl) Is DropDownList Then
AddHandler CType(ctrl, DropDownList).SelectedIndexChanged, AddressOf handleRowChanged
ElseIf TypeOf (ctrl) Is CheckBox Then
AddHandler CType(ctrl, CheckBox).CheckedChanged, AddressOf handleRowChanged
End If
Next
End Sub
Sub handleRowChanged(ByVal sender As Object, ByVal args As EventArgs)
Dim row As GridViewRow = CType(sender, Control).NamingContainer
If row IsNot Nothing And Not dirtyRows.Contains(row.RowIndex) Then
dirtyRows.Add(row.RowIndex)
End If
End Sub
Private dirtyRows As New System.Collections.Generic.List(Of Integer)
Public Sub save()
For Each row As Integer In dirtyRows
Me.UpdateRow(row, False)
Next
dirtyRows.Clear()
End Sub
Private Sub SaveClicked(ByVal sender As Object, ByVal e As System.EventArgs)
Me.save()
Me.DataBind()
End Sub
Private Function RecursiveFindControl(ByVal root As Control, ByVal id As String) As Control
If root.ID = id Then
Return root
End If
For Each c As Control In root.Controls
Dim t As Control = RecursiveFindControl(c, id)
If t IsNot Nothing Then
Return t
End If
Next
Return Nothing
End Function
End Class
--------------------
错误信息如下:
Error1'ReadStringResource' is not a member of 'ASP.bulkeditgridview_ascx'.C:\Documents and Settings\jimmybai\Local Settings\Temp\Temporary ASP.NET Files\cip\a62ce21d\a6805e18\App_Web__xv5fhem.7.vb66
Error1property 'SupportAutoEvents' cannot be declared 'Overrides' because it does not override a property in a base class.C:\Documents and Settings\jimmybai\Local Settings\Temp\Temporary ASP.NET Files\cip\a62ce21d\a6805e18\App_Web_jyvfzmz1.0.vb68
啥问题引起的?
这是有关这些代码的介绍:
http://blogs.msdn.com/mattdotson/articles/490868.aspx
为啥编译时出错呢?那有问题?