⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 validatedgridview.aspx.vb

📁 wrox出版社的另一套经典的VB2005数据库编程学习书籍,收集了书中源码,郑重推荐,电子书,电子书下载
💻 VB
字号:
Option Explicit On
Option Strict On

Partial Class ValidatedGridView_aspx
    Inherits System.Web.UI.Page

    Private Sub gvOrdersEditable_PageIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles gvOrdersEditable.PageIndexChanged
        'Hide error message
        txtError.Visible = False
    End Sub

    Private Sub gvOrdersEditable_RowUpdated(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewUpdatedEventArgs) Handles gvOrdersEditable.RowUpdated
        'Display error message if exception occurs
        If e.Exception Is Nothing Then
            txtError.Text = "No Error"
            txtError.Visible = False
        Else
            txtError.Visible = True
            txtError.Text = "Error: " + Mid(e.Exception.Message, 1, e.Exception.Message.IndexOf("."))
            e.ExceptionHandled = True
        End If
    End Sub

    Private Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        If IsPostBack Then
            'Accumulate number of postbacks
            txtPostBacks.Text = (Val(txtPostBacks.Text) + 1).ToString
        End If
    End Sub

    Sub cvFreight_ServerValidate(ByVal source As Object, ByVal args As System.Web.UI.WebControls.ServerValidateEventArgs)
        'Invalid if order has shipped and Freight < $5.00
        args.IsValid = True
        If Val(args.Value) < 5 Then
            With gvOrdersEditable
                'Get the edited GridViewRow from its EditIndex property
                Dim gvrRow As GridViewRow = .Rows(.EditIndex)
                'Obtain a TextBox control from the row's ShippedDate text box
                Dim txtShipped As TextBox = CType(gvrRow.FindControl("txtShippedDate"), TextBox)
                If txtShipped IsNot Nothing Then
                    If Len(txtShipped.Text) > 4 Then
                        'Order has been shipped
                        args.IsValid = False
                    End If
                End If
            End With
        End If
    End Sub

    Private Sub gvOrdersEditable_RowUpdating(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewUpdateEventArgs) Handles gvOrdersEditable.RowUpdating
        'Dim strRegEx As String = "((0?[13578]|10|12)(\/)((0[0-9])|([12])([0-9]?)|(3[01]?))(\/)((\d{4}))|(0?[2469]|11)(\/)((0[0-9])|([12])([0-9]?)|(3[0]?))(\/)((\d{4})))"
        Dim strRegEx As String = "^((((0?[13578])|(1[02]))\/?((0?[1-9]|[0-2][0-9])|(3[01])))|(((0?[469])|(11))[\/|\-]?((0?[1-9]|[0-2][0-9])|(30)))|(0?[2]\/?(0?[1-9]|[0-2][0-9])))[\/\-]?\d{4}$"
        Dim strDates(5) As String
        'OrderDate
        strDates(0) = e.OldValues.Item(2).ToString
        'RequiredDate
        strDates(1) = e.OldValues.Item(3).ToString
        'ShippedDate
        strDates(2) = e.OldValues.Item(4).ToString
        If e.NewValues IsNot Nothing Then
            'OrderDate
            strDates(3) = e.OldValues.Item(2).ToString
            'RequiredDate
            strDates(4) = e.OldValues.Item(3).ToString
            'ShippedDate
            strDates(5) = e.OldValues.Item(4).ToString
        End If
        Dim intCtr As Integer
        Dim strTest As String = Nothing
        For intCtr = 0 To 5
            If strDates(intCtr).Length > 0 Then
                strTest += strDates(intCtr)
                If Regex.IsMatch(strDates(intCtr), strRegEx) Then
                    strTest += " (Match);"
                Else
                    strTest += " (No Match);"
                End If
            Else
                strTest += "Missing;"
            End If
        Next
    End Sub
End Class

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -