Export (0) Print
Expand All

CompositeDataBoundControl Class

Represents the base class for a tabular data-bound control that is composed of other server controls.

Namespace: System.Web.UI.WebControls
Assembly: System.Web (in system.web.dll)

'Declaration
Public MustInherit Class CompositeDataBoundControl
	Inherits DataBoundControl
	Implements INamingContainer
'Usage
Dim instance As CompositeDataBoundControl

public abstract class CompositeDataBoundControl extends DataBoundControl implements INamingContainer
public abstract class CompositeDataBoundControl extends DataBoundControl implements INamingContainer
Not applicable.

The CompositeDataBoundControl class serves as the base class for a composite server control that binds to data from a data source. A composite server control is a control that is built from a combination of other server controls. Page developers do not use the CompositeDataBoundControl class directly; instead, they use controls that derive from this class. Examples of composite data-bound controls include the DetailsView, FormView, and GridView controls.

Classes that inherit from the CompositeDataBoundControl control must override the CreateChildControls(IEnumerable,Boolean) method to create the control hierarchy. To access the child controls of a composite data-bound control, use the Controls collection.

Notes to Inheritors: When you inherit from the CompositeDataBoundControl class, you must override the following member: CreateChildControls(IEnumerable,Boolean).

The following code example demonstrates how to create a custom composite data-bound control that displays the values of a data source in a table.

Imports System
Imports System.Collections
Imports System.Data.Common
Imports System.Web.UI
Imports System.Web.UI.WebControls

Namespace Samples.AspNet.VB

    Public Class SimpleSpreadsheetControl
        Inherits CompositeDataBoundControl

        Protected table As New Table()

        Public Overridable ReadOnly Property Rows() As TableRowCollection
            Get
                Return table.Rows
            End Get
        End Property


        Protected Overrides Function CreateChildControls(ByVal dataSource As IEnumerable, ByVal dataBinding As Boolean) As Integer

            Dim count As Integer = 0
            ' If dataSource is not Nothing, iterate through it and
            ' extract each element from it as a row, then
            ' create a SimpleSpreadsheetRow and add it to the
            ' rows collection.
            If Not (dataSource Is Nothing) Then

                Dim row As SimpleSpreadsheetRow
                Dim e As IEnumerator = dataSource.GetEnumerator()

                While e.MoveNext()
                    Dim datarow As Object = e.Current
                    row = New SimpleSpreadsheetRow(count, datarow)
                    Me.Rows.Add(row)
                    count += 1
                End While

                Controls.Add(table)
            End If
            Return count
        End Function 'CreateChildControls
    End Class 'SimpleSpreadsheetControl


    Public Class SimpleSpreadsheetRow
        Inherits TableRow
        Implements IDataItemContainer

        Private dataObj As Object
        Private _itemIndex As Integer

        Public Sub New(ByVal itemIndex As Integer, ByVal o As Object)
            dataObj = o
            _itemIndex = itemIndex
        End Sub 'New

        Public Overridable ReadOnly Property Data() As Object
            Get
                Return dataObj
            End Get
        End Property

        ReadOnly Property DataItem() As Object Implements IDataItemContainer.DataItem
            Get
                Return Data
            End Get
        End Property

        ReadOnly Property DataItemIndex() As Integer Implements IDataItemContainer.DataItemIndex
            Get
                Return _itemIndex
            End Get
        End Property

        ReadOnly Property DisplayIndex() As Integer Implements IDataItemContainer.DisplayIndex
            Get
                Return _itemIndex
            End Get
        End Property
        Protected Overrides Sub RenderContents(ByVal writer As HtmlTextWriter)

            If Not (Data Is Nothing) Then
                If TypeOf Data Is System.Data.Common.DbDataRecord Then
                    Dim temp As DbDataRecord = CType(Data, DbDataRecord)
                    Dim i As Integer

                    While i < temp.FieldCount
                        writer.Write("<TD>")
                        writer.Write(temp.GetValue(i).ToString())
                        writer.Write("</TD>")
                        i += 1
                    End While
                Else
                    writer.Write(("<TD>" + Data.ToString() + "</TD>"))
                End If

            Else
                writer.Write("<TD>This is a test</TD>")
            End If
        End Sub 'RenderContents
    End Class 'SimpleSpreadsheetRow
End Namespace

System.Object
   System.Web.UI.Control
     System.Web.UI.WebControls.WebControl
       System.Web.UI.WebControls.BaseDataBoundControl
         System.Web.UI.WebControls.DataBoundControl
          System.Web.UI.WebControls.CompositeDataBoundControl
             System.Web.UI.WebControls.DetailsView
             System.Web.UI.WebControls.FormView
             System.Web.UI.WebControls.GridView

Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.

Windows 98, Windows Server 2000 SP4, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition

The Microsoft .NET Framework 3.0 is supported on Windows Vista, Microsoft Windows XP SP2, and Windows Server 2003 SP1.

.NET Framework

Supported in: 3.0, 2.0

Community Additions

ADD
Show:
© 2014 Microsoft