IDataItemContainer 인터페이스

정의

데이터 바인딩된 컨트롤 컨테이너에서 단순화된 데이터 바인딩 작업에 대한 데이터 항목 개체를 식별할 수 있도록 합니다.Enables data-bound control containers to identify a data item object for simplified data-binding operations.

public interface class IDataItemContainer : System::Web::UI::INamingContainer
public interface IDataItemContainer : System.Web.UI.INamingContainer
type IDataItemContainer = interface
    interface INamingContainer
Public Interface IDataItemContainer
Implements INamingContainer
파생
구현

예제

다음 코드 예제를 사용 하는 방법에 설명 합니다 IDataItemContainer 인터페이스입니다.The following code example demonstrates how to use the IDataItemContainer interface. 합니다 SimpleSpreadsheetControl 유사한 테이블 형식의 데이터를 표시 하는 컨트롤은는 DataGrid 또는 GridView 제어 합니다.The SimpleSpreadsheetControl is a control that displays tabular-style data, similar to a DataGrid or GridView control. 집합을 포함 SimpleSpreadsheetRow 개체입니다.It contains a set of SimpleSpreadsheetRow objects.

합니다 SimpleSpreadsheetRow 클래스는 구현 하는 컨테이너 클래스는 IDataItemContainer 인터페이스입니다.The SimpleSpreadsheetRow class is a container class that implements the IDataItemContainer interface. 이 예제에서 데이터 항목 속성 이름은 직관적으로 하지만 Data, DataItem 메서드의 모든 속성 또는 반환 값에 매핑할 속성을 구현할 수 있습니다.Although in this example the data item property is intuitively named Data, the DataItem property can be implemented to map to any property or return value of a method.

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


    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
End Namespace

다음 코드 예제를 사용 하는 방법에 설명 합니다 SimpleSpreadsheetControlAccessDataSource Access 데이터베이스에서 데이터를 표시 하는 컨트롤입니다.The following code example demonstrates how to use the SimpleSpreadsheetControl and AccessDataSource control to display data in an Access database.

<%@ Register TagPrefix="aspSample" Namespace="Samples.AspNet.CS"
    Assembly="Samples.AspNet.CS"  %>
<%@ Page language="c#" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
  <head>
    <title>IDataItemContainer - C# Example</title>
  </head>
  <body>
    <form id="Form1" method="post" runat="server">

      <aspSample:SimpleSpreadsheetControl
          id="SimpleSpreadsheet1"
          runat="server"
          datasourceid="AccessDataSource1" />

      <asp:accessdatasource
          id="AccessDataSource1"
          runat="server"
          datasourcemode="DataReader"
          datafile="Northwind.mdb"
          SelectCommand="SELECT OrderID,CustomerID,OrderDate,RequiredDate,
          ShippedDate FROM Orders WHERE EmployeeID = (SELECT EmployeeID 
          FROM Employees WHERE LastName = 'King')">
      </asp:accessdatasource>

    </form>
  </body>
</html>
<%@ Register TagPrefix="aspSample" Namespace="Samples.AspNet.VB"
    Assembly="Samples.AspNet.VB" %>
<%@ Page language="vb" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
  <head>
    <title>IDataItemContainer - VB Example</title>
  </head>
  <body>
    <form id="Form1" method="post" runat="server">

      <aspSample:SimpleSpreadsheetControl
          id="SimpleSpreadsheet1"
          runat="server"
          datasourceid="AccessDataSource1" />

      <asp:accessdatasource
          id="AccessDataSource1"
          runat="server"
          datasourcemode="DataReader"
          datafile="Northwind.mdb"
          SelectCommand="SELECT OrderID,CustomerID,OrderDate,RequiredDate,ShippedDate
          FROM Orders WHERE EmployeeID =
          (SELECT EmployeeID FROM Employees WHERE LastName = 'King')">
      </asp:accessdatasource>

    </form>
  </body>
</html>

설명

컨테이너에 구현 하는 클래스를 IDataItemContainer 인터페이스 사용 하 여 런타임에 바인딩 등의 데이터 바인딩 작업에 대 한 데이터 항목을 식별 하는 속성을 지정할 수는 DataBinder 클래스.Container classes that implement the IDataItemContainer interface can specify which of their properties identifies the data item for data-binding operations, such as late binding with the DataBinder class.

속성

DataItem

구현될 때 단순화된 데이터 바인딩 작업에 사용되는 object를 가져옵니다.When implemented, gets an object that is used in simplified data-binding operations.

DataItemIndex

구현될 때 컨트롤에 바인딩된 데이터 항목의 인덱스를 가져옵니다.When implemented, gets the index of the data item bound to a control.

DisplayIndex

구현될 때 데이터 항목의 위치를 컨트롤에 표시된 대로 가져옵니다.When implemented, gets the position of the data item as displayed in a control.

확장 메서드

GetDefaultValues(INamingContainer)

지정된 데이터 컨트롤의 기본값에 대한 컬렉션을 가져옵니다.Gets the collection of the default values for the specified data control.

GetMetaTable(INamingContainer)

지정한 데이터 컨트롤에 대한 테이블 메타데이터를 가져옵니다.Gets the table metadata for the specified data control.

SetMetaTable(INamingContainer, MetaTable)

지정한 데이터 컨트롤에 대한 테이블 메타데이터를 설정합니다.Sets the table metadata for the specified data control.

SetMetaTable(INamingContainer, MetaTable, IDictionary<String,Object>)

지정된 데이터 컨트롤에 대한 테이블 메타데이터 및 기본값 매핑을 설정합니다.Sets the table metadata and default value mapping for the specified data control.

SetMetaTable(INamingContainer, MetaTable, Object)

지정된 데이터 컨트롤에 대한 테이블 메타데이터 및 기본값 매핑을 설정합니다.Sets the table metadata and default value mapping for the specified data control.

TryGetMetaTable(INamingContainer, MetaTable)

테이블 메타데이터를 사용할 수 있는지 여부를 결정합니다.Determines whether table metadata is available.

EnableDynamicData(INamingContainer, Type)

지정된 데이터 컨트롤에 Dynamic Data 동작을 사용하도록 설정합니다.Enables Dynamic Data behavior for the specified data control.

EnableDynamicData(INamingContainer, Type, IDictionary<String,Object>)

지정된 데이터 컨트롤에 Dynamic Data 동작을 사용하도록 설정합니다.Enables Dynamic Data behavior for the specified data control.

EnableDynamicData(INamingContainer, Type, Object)

지정된 데이터 컨트롤에 Dynamic Data 동작을 사용하도록 설정합니다.Enables Dynamic Data behavior for the specified data control.

적용 대상

추가 정보