MyGridViewRow Class - ASP.NET

This page is part of the Class Library Pages collection.
Click the icon to see the index.

Sample Implementation

In the GridView's RowDataBound event handler...

Dim g As MyGridViewRow = New MyGridViewRow(e.Row)
Dim d As MyDataSet.MyRow = g.DataRow
g.uxOrderIdLabel.Text = d.OrderId.ToString()

' TODO: Populate other controls similarly.

Source Code


Imports Microsoft.VisualBasic
Imports System.Data

Public Class MyGridViewRow

    Private _gvRow As GridViewRow

    '== Constructor and Public Methods ============================================================
    Public Sub New(ByVal gvRow As GridViewRow)

        _gvRow = gvRow

    End Sub
    Public ReadOnly Property DataRow() As MyDataSet.MyRow
            Return CType(CType(_gvRow.DataItem, DataRowView).Row, MyDataSet.MyRow)
        End Get
    End Property

    '== Private Functions =========================================================================
    Private Function FindControl(Of ControlType As {Control})(ByVal id As String) As ControlType

        Dim result As ControlType = Nothing
        Dim ctl As Object = _gvRow.FindControl(id)

        If ctl IsNot Nothing Then
            result = CType(ctl, ControlType)
        End If

        Return result

    End Function

    '== Control Properties ========================================================================
    '   TODO: Create one read-only property per control on your grid view row
    Public ReadOnly Property uxNameLabel() As Label
            Return FindControl(Of Label)("uxNameLabel")
        End Get
    End Property

End Class