RowToFieldTransformer Class


Transforms data in a Web Parts connection from a provider that implements the IWebPartRow interface to a consumer expecting data through the IWebPartField interface.

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


<WebPartTransformerAttribute(GetType(IWebPartRow), GetType(IWebPartField))>
Public NotInheritable Class RowToFieldTransformer
	Inherits WebPartTransformer
	Implements IWebPartField


Initializes a new instance of the RowToFieldTransformer class.


Gets or sets the name of the value to transform.


Displays an ASP.NET control that configures a RowToFieldTransformer transformer in the ConnectionsZone zone.(Overrides WebPartTransformer.CreateConfigurationControl().)


Determines whether the specified object is equal to the current object.(Inherited from Object.)


Serves as the default hash function. (Inherited from Object.)


Gets the Type of the current instance.(Inherited from Object.)


Loads the configuration state saved with the SaveConfigurationState method.(Inherited from WebPartTransformer.)


Saves the configuration state set by the user in the ASP.NET configuration control. (Inherited from WebPartTransformer.)


Returns a string that represents the current object.(Inherited from Object.)


Provides an object for transforming the data.(Overrides WebPartTransformer.Transform(Object).)


Returns the value of the field that is being used by the interface as the basis of a connection between two Web Parts controls.


Gets the schema information for a data field that is used to share data between two Web Parts controls.

Transformers are used to translate data between two Web Parts controls with incompatible connection points. A RowToFieldTransformer object transforms data from a provider implementing the IWebPartRow interface to a consumer requiring data from the IWebPartField interface. The RowToFieldTransformer class allows controls with these incompatible connection points to be connected.

The following code example demonstrates how to use a RowToFieldTransformer object to connect a provider and consumer with incompatible connection points. The first section of the example shows a Web Parts control that serves as a provider. The provider class, named RowProviderWebPart, provides data through the IWebPartRow interface.

Imports System
Imports System.Collections
Imports System.ComponentModel
Imports System.Data
Imports System.Reflection
Imports System.Web.UI
Imports System.Web.UI.WebControls
Imports System.Web.UI.WebControls.WebParts

'This sample code creates a Web Parts control that acts as a provider of row data.
Namespace Samples.AspNet.VB.Controls

    Public NotInheritable Class RowProviderWebPart
        Inherits WebPart
        Implements IWebPartRow

        Private _table As DataTable

        Public Sub New()
            _table = New DataTable()

            Dim col As New DataColumn()
            col.DataType = GetType(String)
            col.ColumnName = "Name"

            col = New DataColumn()
            col.DataType = GetType(String)
            col.ColumnName = "Address"

            col = New DataColumn()
            col.DataType = GetType(Integer)
            col.ColumnName = "ZIP Code"

            Dim row As DataRow = _table.NewRow()
            row("Name") = "John Q. Public"
            row("Address") = "123 Main Street"
            row("ZIP Code") = 98000

        End Sub 'NewNew

        <ConnectionProvider("Row")> _
        Public Function GetConnectionInterface() As IWebPartRow
            Return New RowProviderWebPart()

        End Function 'GetConnectionInterface

        Public ReadOnly Property Schema() As PropertyDescriptorCollection _
            Implements IWebPartRow.Schema
                Return TypeDescriptor.GetProperties(_table.DefaultView(0))
            End Get
        End Property

        Public Sub GetRowData(ByVal callback As RowCallback) _
            Implements IWebPartRow.GetRowData

        End Sub 'GetRowData
    End Class 'RowProviderWebPart           

End Namespace

The second section of the example contains a Web Parts control that is a consumer of a Web Parts connection. The consumer class, named FieldConsumerWebPart, expects data from the IWebPartField interface.

Imports System
Imports System.ComponentModel
Imports System.Reflection
Imports System.Collections
Imports System.Data
Imports System.Web.UI
Imports System.Web.UI.WebControls
Imports System.Web.UI.WebControls.WebParts

Namespace Samples.AspNet.VB.Controls
    ' This sample code creates a Web Parts control that acts as 
    ' a consumer of an IField interface.

    Public Class FieldConsumerWebPart
        Inherits WebPart

        Private _provider As IWebPartField
        Private _fieldValue As Object

        Private Sub GetFieldValue(ByVal fieldValue As Object)
            _fieldValue = fieldValue

        End Sub 'GetFieldValue

        Protected Overrides Sub OnPreRender(ByVal e As EventArgs)
            If Not (_provider Is Nothing) Then
                _provider.GetFieldValue((New FieldCallback(AddressOf GetFieldValue)))
            End If

        End Sub 'OnPreRender

        Protected Overrides Sub RenderContents(ByVal writer As HtmlTextWriter)

            If Not (_provider Is Nothing) Then
                Dim prop As PropertyDescriptor = _provider.Schema

                If Not (prop Is Nothing) AndAlso Not (_fieldValue Is Nothing) Then
                    writer.Write(prop.DisplayName & ": " & _fieldValue)
                    writer.Write("No data")
                End If
                writer.Write("Not connected")
            End If

        End Sub 'RenderContents

        <ConnectionConsumer("Field")> _
        Public Sub SetConnectionInterface(ByVal provider As IWebPartField)
            _provider = provider

        End Sub 'SetConnectionInterface

        Private Class FieldConsumerConnectionPoint
            Inherits ConsumerConnectionPoint

            Public Sub New(ByVal callbackMethod As MethodInfo, _
              ByVal interfaceType As Type, ByVal controlType As Type, _
              ByVal name As String, ByVal id As String, _
              ByVal allowsMultipleConnections As Boolean)
                MyBase.New(callbackMethod, interfaceType, controlType, _
                  name, id, allowsMultipleConnections)

            End Sub 'NewNew
        End Class 'FieldConsumerConnectionPoint 
    End Class 'FieldConsumerWebPart

The third section of the example shows a page that contains the two controls and defines the RowToFieldTransformer object for connecting the two controls.

<%@ Page Language="VB" %>
<%@ register tagprefix="uc1" 
    src="~/displaymodemenuvb.ascx" %>
<%@ Register TagPrefix="wp" 
    NameSpace="Samples.AspNet.VB.Controls" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "">

<script runat="server">


<html xmlns="" >
<head id="Head1" runat="server">
    <title>Untitled Page</title>
  <form id="form1" runat="server">
    <asp:webpartmanager id="manager" runat="server">
      <asp:WebPartConnection ID="conn1" ProviderID="rp1" ConsumerID="fc1">
        <asp:RowToFieldTransformer FieldName="Zip Code"/>
  <uc1:displaymodemenuvb id="menu1" runat="server" />
  <tr valign="top">
      <asp:webpartzone id="zone1" headertext="zone1" runat="server">
          <wp:RowProviderWebPart Title="provider" ID="rp1" runat="server" />
          <wp:FieldConsumerWebPart Title="consumer" ID="fc1" runat="server" />
      <asp:connectionszone id="connectionszone1" runat="server" />


The code example includes a user control that enables you to change display modes on a Web Parts page. The source code for the user control comes from another topic. You can obtain the .ascx file for the user control from Walkthrough: Changing Display Modes on a Web Parts Page, and it must be placed in the same folder as the .aspx page.

.NET Framework
Available since 2.0

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

Return to top