CompositeDataBoundControl.CreateChildControls CompositeDataBoundControl.CreateChildControls CompositeDataBoundControl.CreateChildControls CompositeDataBoundControl.CreateChildControls Method

Definición

Crea la jerarquía de controles que se utiliza para procesar un control compuesto enlazado a datos.Creates the control hierarchy that is used to render a composite data-bound control.

Sobrecargas

CreateChildControls() CreateChildControls() CreateChildControls() CreateChildControls()

Crea la jerarquía de controles que se utiliza para procesar un control compuesto enlazado a datos basada en los valores que se almacenan en estado de vista.Creates the control hierarchy that is used to render a composite data-bound control based on the values that are stored in view state.

CreateChildControls(IEnumerable, Boolean) CreateChildControls(IEnumerable, Boolean) CreateChildControls(IEnumerable, Boolean) CreateChildControls(IEnumerable, Boolean)

Cuando se reemplaza en una clase abstracta, crea la jerarquía de controles que se utiliza para procesar un control compuesto enlazado a datos basándose en los valores del origen de datos especificado.When overridden in an abstract class, creates the control hierarchy that is used to render the composite data-bound control based on the values from the specified data source.

CreateChildControls() CreateChildControls() CreateChildControls() CreateChildControls()

Crea la jerarquía de controles que se utiliza para procesar un control compuesto enlazado a datos basada en los valores que se almacenan en estado de vista.Creates the control hierarchy that is used to render a composite data-bound control based on the values that are stored in view state.

protected public:
 override void CreateChildControls();
protected internal override void CreateChildControls ();
override this.CreateChildControls : unit -> unit
Protected Friend Overrides Sub CreateChildControls ()

Comentarios

El CreateChildControls() método es un método auxiliar que utilizan las clases que derivan de la CompositeDataBoundControl clase para crear la jerarquía de controles de un control compuesto enlazado a datos.The CreateChildControls() method is a helper method that is used by classes that derive from the CompositeDataBoundControl class to create the control hierarchy for a composite data-bound control. Esta sobrecarga del método crea la jerarquía de controles basándose en los valores del estado de vista, en lugar de hacerlo directamente desde el origen de datos.This overload of the method creates the control hierarchy based on values from view state, rather than directly from the data source.

Consulte también:

CreateChildControls(IEnumerable, Boolean) CreateChildControls(IEnumerable, Boolean) CreateChildControls(IEnumerable, Boolean) CreateChildControls(IEnumerable, Boolean)

Cuando se reemplaza en una clase abstracta, crea la jerarquía de controles que se utiliza para procesar un control compuesto enlazado a datos basándose en los valores del origen de datos especificado.When overridden in an abstract class, creates the control hierarchy that is used to render the composite data-bound control based on the values from the specified data source.

protected:
 abstract int CreateChildControls(System::Collections::IEnumerable ^ dataSource, bool dataBinding);
protected abstract int CreateChildControls (System.Collections.IEnumerable dataSource, bool dataBinding);
override this.CreateChildControls : System.Collections.IEnumerable * bool -> int
Protected MustOverride Function CreateChildControls (dataSource As IEnumerable, dataBinding As Boolean) As Integer

Parámetros

dataSource
IEnumerable IEnumerable IEnumerable IEnumerable

Una interfaz IEnumerable que contiene los valores para enlazarse al control.An IEnumerable that contains the values to bind to the control.

dataBinding
Boolean Boolean Boolean Boolean

Es true para indicar que el método CreateChildControls(IEnumerable, Boolean) recibe una llamada durante el enlace de datos; de lo contrario, es false.true to indicate that the CreateChildControls(IEnumerable, Boolean) is called during data binding; otherwise, false.

Devoluciones

Número de elementos creados por el método CreateChildControls(IEnumerable, Boolean).The number of items created by the CreateChildControls(IEnumerable, Boolean).

Ejemplos

En el ejemplo de código siguiente se muestra cómo CreateChildControls(IEnumerable, Boolean) invalidar el método en un control personalizado para crear la jerarquía de controles.The following code example demonstrates how to override the CreateChildControls(IEnumerable, Boolean) method in a custom control to create the control hierarchy.

using System;
using System.Collections;
using System.Data.Common;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace Samples.AspNet.CS
{
    public class SimpleSpreadsheetControl : CompositeDataBoundControl
    {
        protected Table table = new Table();

        public virtual TableRowCollection Rows
        {
            get
            {
                return table.Rows;
            }
        }

        protected override int CreateChildControls(IEnumerable dataSource, bool dataBinding)
        {

            int count = 0;
            // If dataSource is not null, iterate through it and
            // extract each element from it as a row, then
            // create a SimpleSpreadsheetRow and add it to the
            // rows collection.
            if (dataSource != null)
            {

                SimpleSpreadsheetRow row;
                IEnumerator e = dataSource.GetEnumerator();

                while (e.MoveNext())
                {
                    object datarow = e.Current;
                    row = new SimpleSpreadsheetRow(count, datarow);
                    this.Rows.Add(row);
                    ++count;
                }

                Controls.Add(table);
            }
            return count;
        }
    }

    //
    //
    public class SimpleSpreadsheetRow : TableRow, IDataItemContainer
    {
        private object data;
        private int _itemIndex;

        public SimpleSpreadsheetRow(int itemIndex, object o)
        {
            data = o;
            _itemIndex = itemIndex;
        }

        public virtual object Data
        {
            get
            {
                return data;
            }
        }
        object IDataItemContainer.DataItem
        {
            get
            {
                return Data;
            }
        }
        int IDataItemContainer.DataItemIndex
        {
            get
            {
                return _itemIndex;
            }
        }
        int IDataItemContainer.DisplayIndex
        {
            get
            {
                return _itemIndex;
            }
        }
        protected override void RenderContents(HtmlTextWriter writer)
        {

            if (Data != null)
            {
                if (Data is System.Data.Common.DbDataRecord)
                {
                    DbDataRecord temp = (DbDataRecord)Data;
                    for (int i = 0; i < temp.FieldCount; ++i)
                    {
                        writer.Write("<TD>");
                        writer.Write(temp.GetValue(i).ToString());
                        writer.Write("</TD>");
                    }
                }
                else
                    writer.Write("<TD>" + Data.ToString() + "</TD>");
            }

            else
                writer.Write("<TD>This is a test</TD>");
        }
    }
}
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

        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
    End Class 'SimpleSpreadsheetRow
End Namespace

Comentarios

El CreateChildControls() método es un método auxiliar que utilizan las clases que derivan de la CompositeDataBoundControl clase para crear la jerarquía de controles de un control compuesto enlazado a datos.The CreateChildControls() method is a helper method that is used by classes that derive from the CompositeDataBoundControl class to create the control hierarchy for a composite data-bound control. Al extender la CompositeDataBoundControl clase, debe invalidar el CreateChildControls() método para crear su propia jerarquía de controles.When extending the CompositeDataBoundControl class, you must override the CreateChildControls() method to create your own control hierarchy. Para obtener más información sobre cómo crear un control compuesto, vea desarrollar controles de servidor ASP.net personalizados.For more information on creating a composite control, see Developing Custom ASP.NET Server Controls.

Consulte también:

Se aplica a