Tutorials on Itemplate

Greetings, I build a GridView in VB to display on an aspx page, and I'm intrested in adding a TemplateField to extend some functionality.
I need to define a class that implements ITemplate to hold the content of my ItemTemplate, and I'm looking for any good tutorials that would show me how to do this sort of thing.  Thanks very much.
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Bob LearnedCommented:
Bob LearnedCommented:
Here is the translated VB.NET code:

Imports System.Data
Imports Microsoft.VisualBasic

Public Class Template
  Implements ITemplate

  Private m_checkBox As CheckBox

  Public Event CheckedChanged As EventHandler

  Private m_readOnly As Boolean = False
  Public Sub New(ByVal editable As Boolean)

    m_readOnly = Not editable

  End Sub

  Public Sub InstantiateIn(ByVal container As System.Web.UI.Control) Implements System.Web.UI.ITemplate.InstantiateIn

    Dim m_checkBox As New CheckBox

    AddHandler m_checkBox.DataBinding, AddressOf BindData
    AddHandler m_checkBox.CheckedChanged, AddressOf OnCheckChanged

  End Sub

  Public Property AutoPostBack() As Boolean
      Return m_checkBox.AutoPostBack
    End Get
    Set(ByVal value As Boolean)
      m_checkBox.AutoPostBack = value
    End Set
  End Property

  Private m_dataField As String = ""

  Public Property DataField() As String
      Return m_dataField
    End Get
    Set(ByVal value As String)
      m_dataField = value
    End Set
  End Property 'DataField

  Private Sub BindData(ByVal sender As Object, ByVal e As EventArgs)

    Dim container As DataGridItem = CType(m_checkBox.NamingContainer, DataGridItem)

    m_checkBox.Checked = False
    m_checkBox.Enabled = Not m_readOnly

    Dim data As String = CType(container.DataItem, DataRowView)(Me.DataField).ToString()
    Dim type As Type = CType(container.DataItem, DataRowView).DataView.Table.Columns(Me.DataField).DataType

    If data.Length > 0 Then
      Select Case type.ToString()
        Case "System.Boolean"
          If data = "True" Then
            m_checkBox.Checked = True
          End If
        Case Else
      End Select
    End If
  End Sub

  Public Sub OnCheckChanged(ByVal sender As Object, ByVal e As EventArgs)

    RaiseEvent CheckedChanged(sender, e)

  End Sub

End Class


Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
ChaffeAuthor Commented:
Bob, this code is going to save me a lot of work.  thanks a bunch..
Since this is done on a dataGrid, Do you happen to know what the GridView equivilent of:
DataGridItem & DataRowView.
Bob LearnedCommented:
I am not 100% sure, but I believe that the equivalent is GridViewRow.  DataRowView should still be the same, but that depends on what type 'container.DataItem' is.

ChaffeAuthor Commented:
Bob, thanks for the help.
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic.NET

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.