Duration (Pacific Standard Time):
To (Pacific Standard Time):
Impact:
User Action:

IDataItemContainer Interface

 

Enables data-bound control containers to identify a data item object for simplified data-binding operations.

Namespace:   System.Web.UI
Assembly:  System.Web (in System.Web.dll)

Public Interface IDataItemContainer
	Inherits INamingContainer
Name Description
System_CAPS_pubproperty DataItem

When implemented, gets an object that is used in simplified data-binding operations.

System_CAPS_pubproperty DataItemIndex

When implemented, gets the index of the data item bound to a control.

System_CAPS_pubproperty DisplayIndex

When implemented, gets the position of the data item as displayed in a control.

Name Description
System_CAPS_pubmethod EnableDynamicData(Type)

Overloaded. Enables Dynamic Data behavior for the specified data control.(Defined by DataControlExtensions.)

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

Overloaded. Enables Dynamic Data behavior for the specified data control.(Defined by DataControlExtensions.)

System_CAPS_pubmethod EnableDynamicData(Type, Object)

Overloaded. Enables Dynamic Data behavior for the specified data control.(Defined by DataControlExtensions.)

System_CAPS_pubmethod GetDefaultValues()

Overloaded. Gets the collection of the default values for the specified data control.(Defined by DynamicDataExtensions.)

System_CAPS_pubmethod GetMetaTable()

Overloaded. Gets the table metadata for the specified data control.(Defined by DynamicDataExtensions.)

System_CAPS_pubmethod SetMetaTable(MetaTable)

Overloaded. Sets the table metadata for the specified data control.(Defined by DynamicDataExtensions.)

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

Overloaded. Sets the table metadata and default value mapping for the specified data control.(Defined by DynamicDataExtensions.)

System_CAPS_pubmethod SetMetaTable(MetaTable, Object)

Overloaded. Sets the table metadata and default value mapping for the specified data control.(Defined by DynamicDataExtensions.)

System_CAPS_pubmethod TryGetMetaTable(MetaTable)

Overloaded. Determines whether table metadata is available.(Defined by DynamicDataExtensions.)

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.

The following code example demonstrates how to use the IDataItemContainer interface. The SimpleSpreadsheetControl is a control that displays tabular-style data, similar to a DataGrid or GridView control. It contains a set of SimpleSpreadsheetRow objects.

The SimpleSpreadsheetRow class is a container class that implements the IDataItemContainer interface. 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.

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 'NewNew

        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

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.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>
.NET Framework
Available since 2.0
Return to top