Jasinski Technical Wiki

Navigation

Home Page
Index
All Pages

Quick Search
»
Advanced Search »

Contributor Links

Create a new Page
Administration
File Management
Login/Logout
Your Profile

Other Wiki Sections

Software

PoweredBy

GridViewRowExtender Class

RSS
Modified on Tue, Dec 01, 2009, 3:07 PM by Administrator Categorized as ASP·NET Web Forms, Class Library
This page is part of the Class Library Pages collection.
Click the icon to see the index.

Source Code

VB.NET

{copytext|SourceVb}
Imports System.Reflection

Public Class GridViewRowExtender

    Private _gvRow As GridViewRow

    Public Sub New(ByVal gvRow As GridViewRow)
        _gvRow = gvRow
    End Sub

    Public Function GetText(ByVal textBoxId As String) As String

        Return CType(_gvRow.FindControl(textBoxId), TextBox).Text

    End Function
    Public Function GetText(Of T)(ByVal textBoxId As String) As T

        Dim s As String = GetText(textBoxId)

        Dim result As T

        If Not TryParse(Of T)(s, result) Then
            result = Nothing
        End If

        Return result

    End Function

    Public Function GetChecked(ByVal checkBoxId As String) As Boolean

        Return CType(_gvRow.FindControl(checkBoxId), CheckBox).Checked

    End Function

    Public Function GetSelectedValue(ByVal dropDownListId As String) As String

        Return CType(_gvRow.FindControl(dropDownListId), DropDownList).SelectedValue

    End Function
    Public Function GetSelectedValue(Of T)(ByVal dropDownListId As String) As T

        Dim s As String = GetSelectedValue(dropDownListId)

        Dim result As T

        If Not TryParse(Of T)(s, result) Then
            result = Nothing
        End If

        Return result

    End Function

    Private Function TryParse(Of T)(ByVal input As String, ByRef value As T) As Boolean

        Dim result As Boolean = False
        Dim type As Type = GetType(T)
        Dim pt As Type() = New Type() {GetType(System.String)}
        Dim mi As MethodInfo = type.GetMethod("Parse", pt)
        value = Nothing

        Try
            value = DirectCast((mi.Invoke(Nothing, New Object() {input})), T)
            result = True
        Catch
        End Try

        Return result

    End Function

End Class

C#

{copytext|SourceCs}
//TODO


ScrewTurn Wiki version 3.0.1.400. Some of the icons created by FamFamFam. Except where noted, all contents Copyright © 1999-2024, Patrick Jasinski.