项目中我认为不错的几个共同方法(设定控件的是否可用,焦点等)

来源:互联网 发布:达内java培训 编辑:程序博客网 时间:2024/05/22 06:37

 ''' <summary>
    ''' 画面上的控件是否可用设定
    ''' </summary>
    ''' <param name="paraControl">控件(VIEW)</param>
    ''' <param name="paraStrCtrlName">画面上控件ID为元素的数组</param>
    ''' <param name="status">设定状态是否可用</param>
    ''' <remarks></remarks>
    Protected Sub setControlsStatus(ByVal paraControl As System.Web.UI.Control, ByVal paraStrCtrlName() As String, ByVal status As Boolean)
        If paraControl Is Nothing Then
            Throw New ArgumentNullException
        End If
        'Control数取得
        Dim intCount As Integer = UBound(paraStrCtrlName)
        Dim ctrlName As String = Nothing
        'VisibleStatus設定
        For i As Integer = 0 To intCount
            ctrlName = paraStrCtrlName(i)
            If ctrlName Is Nothing Then
                Throw New ArgumentNullException
            End If
            Dim objControl As Control = paraControl.FindControl(ctrlName)
            If Not IsNothing(objControl) Then
                Dim strType As String = objControl.GetType().ToString()
                'HTMLコントロールの時
                If Left(strType.Substring(strType.LastIndexOf(".") + 1), 4) = "Html" Then
                    CType(objControl, Object).disabled = Not status
                    'WEBコントロールの時
                Else
                    CType(objControl, Object).enabled = status
                End If
            End If
        Next
    End Sub

    ''' <summary>
    '''  画面上的CheckBox状态的设定
    ''' </summary>
    ''' <param name="paraControl">控件(VIEW)</param>
    ''' <param name="paraStrCtrlName">画面上控件ID为元素的数组</param>
    ''' <param name="status">设定状态是否选中</param>
    ''' <remarks></remarks>
    Protected Sub setCheckStatus(ByVal paraControl As System.Web.UI.Control, ByVal paraStrCtrlName() As String, ByVal status As Boolean)
        If paraControl Is Nothing Then
            Throw New ArgumentNullException
        End If
        'Control数取得
        Dim intCount As Integer = UBound(paraStrCtrlName)
        Dim ctrlName As String = Nothing
        'VisibleStatus設定
        For i As Integer = 0 To intCount
            ctrlName = paraStrCtrlName(i)
            If ctrlName Is Nothing Then
                Throw New ArgumentNullException
            End If
            Dim objControl As Control = paraControl.FindControl(ctrlName)
            If Not IsNothing(objControl) Then
                CType(objControl, CheckBox).Checked = status
            End If
        Next
    End Sub

原创粉丝点击