Export (0) Print
Expand All

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.

System.Object
  System.Web.UI.WebControls.WebParts.WebPartTransformer
    System.Web.UI.WebControls.WebParts.RowToFieldTransformer

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

[WebPartTransformerAttribute(typeof(IWebPartRow), typeof(IWebPartField))]
public sealed class RowToFieldTransformer : WebPartTransformer, 
	IWebPartField

The RowToFieldTransformer type exposes the following members.

  NameDescription
Public methodRowToFieldTransformerInitializes a new instance of the RowToFieldTransformer class.
Top

  NameDescription
Public propertyFieldNameGets or sets the name of the value to transform.
Top

  NameDescription
Public methodCreateConfigurationControlDisplays an ASP.NET control that configures a RowToFieldTransformer transformer in the ConnectionsZone zone. (Overrides WebPartTransformer.CreateConfigurationControl().)
Public methodEquals(Object)Determines whether the specified object is equal to the current object. (Inherited from Object.)
Public methodGetHashCodeServes as the default hash function. (Inherited from Object.)
Public methodGetTypeGets the Type of the current instance. (Inherited from Object.)
Protected methodLoadConfigurationStateLoads the configuration state saved with the SaveConfigurationState method. (Inherited from WebPartTransformer.)
Protected methodSaveConfigurationStateSaves the configuration state set by the user in the ASP.NET configuration control. (Inherited from WebPartTransformer.)
Public methodToStringReturns a string that represents the current object. (Inherited from Object.)
Public methodTransformProvides an object for transforming the data. (Overrides WebPartTransformer.Transform(Object).)
Top

  NameDescription
Explicit interface implemetationPrivate methodIWebPartField.GetFieldValueReturns the value of the field that is being used by the interface as the basis of a connection between two Web Parts controls.
Explicit interface implemetationPrivate propertyIWebPartField.SchemaGets the schema information for a data field that is used to share data between two Web Parts controls.
Top

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.

using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Reflection;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;

//This sample code creates a Web Parts control that acts as a provider of row data. 
namespace Samples.AspNet.CS.Controls
{
    public sealed class RowProviderWebPart : WebPart, IWebPartRow
    {
        private DataTable _table;

        public RowProviderWebPart()
        {
            _table = new DataTable();

            DataColumn col = new DataColumn();
            col.DataType = typeof(string);
            col.ColumnName = "Name";
            _table.Columns.Add(col);

            col = new DataColumn();
            col.DataType = typeof(string);
            col.ColumnName = "Address";
            _table.Columns.Add(col);

            col = new DataColumn();
            col.DataType = typeof(int);
            col.ColumnName = "ZIP Code";
            _table.Columns.Add(col);

            DataRow row = _table.NewRow();
            row["Name"] = "John Q. Public";
            row["Address"] = "123 Main Street";
            row["ZIP Code"] = 98000;
            _table.Rows.Add(row);
        }

        [ConnectionProvider("Row")]
        public IWebPartRow GetConnectionInterface()
        {
            return new RowProviderWebPart();
        }

        public PropertyDescriptorCollection Schema
        {
            get
            {
                return TypeDescriptor.GetProperties(_table.DefaultView[0]);
            }
        }

        public void GetRowData(RowCallback callback)
        {
            callback(_table.DefaultView[0]);
        }          
    }
}

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.

using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Reflection;
using System.Web;
using System.Web.UI;
using System.Security.Permissions;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;

namespace Samples.AspNet.CS.Controls
{

    // This sample code creates a Web Parts control that acts 
    // as a consumer of an IField interface. 

    // A consumer WebPart control that consumes strings.
    [AspNetHostingPermission(SecurityAction.Demand,
      Level = AspNetHostingPermissionLevel.Minimal)]
    [AspNetHostingPermission(SecurityAction.InheritanceDemand,
      Level = AspNetHostingPermissionLevel.Minimal)]
    public class FieldConsumerWebPart : WebPart
    {
        private IWebPartField _provider;
        private object _fieldValue;

        private void GetFieldValue(object fieldValue)
        {
            _fieldValue = fieldValue;
        }

        public bool ConnectionPointEnabled
        {
            get
            {
                object o = ViewState["ConnectionPointEnabled"];
                return (o != null) ? (bool)o : true;
            }
            set
            {
                ViewState["ConnectionPointeEnabled"] = value;
            }
        }

        protected override void OnPreRender(EventArgs e)
        {
            if (_provider != null)
            {
                _provider.GetFieldValue(new FieldCallback(GetFieldValue));
            }
            base.OnPreRender(e);
        }

        protected override void RenderContents(HtmlTextWriter writer)
        {

            if (_provider != null)
            {
                PropertyDescriptor prop = _provider.Schema;

                if (prop != null && _fieldValue != null)
                {
                    writer.Write(prop.DisplayName + ": " + _fieldValue);
                }
                else
                {
                    writer.Write("No data");
                }
            }
            else
            {
                writer.Write("Not connected");
            }
        }

        [ConnectionConsumer("Field")]
        public void SetConnectionInterface(IWebPartField provider)
        {
            _provider = provider;
        }

        private class FieldConsumerConnectionPoint : ConsumerConnectionPoint
        {
            public FieldConsumerConnectionPoint(MethodInfo callbackMethod, Type interfaceType, Type controlType,
                 string name, string id, bool allowsMultipleConnections)
                : base(callbackMethod, interfaceType, controlType,
                       name, id, allowsMultipleConnections)
            {
            }

            public override bool GetEnabled(Control control)
            {
                return ((FieldConsumerWebPart)control).ConnectionPointEnabled;
            }

        }
    }
}

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="C#" %>
<%@ register tagprefix="uc1" 
    tagname="DisplayModeMenuCS" 
    src="~/displaymodemenucs.ascx" %>
<%@ Register TagPrefix="wp" 
    NameSpace="Samples.AspNet.CS.Controls" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<script runat="server">

</script>

<html xmlns="http://www.w3.org/1999/xhtml" >
<head id="Head1" runat="server">
    <title>Untitled Page</title>
</head>
<body>
  <form id="form1" runat="server">
    <asp:webpartmanager id="manager" runat="server">
    <staticconnections>
      <asp:WebPartConnection ID="conn1" ProviderID="rp1" ConsumerID="fc1">
        <asp:RowToFieldTransformer FieldName="Zip Code"/>
      </asp:WebPartConnection>
    </staticconnections>
    </asp:webpartmanager>
  <uc1:displaymodemenucs id="menu1" runat="server" />
  <table>
  <tr valign="top">
    <td>
      <asp:webpartzone id="zone1" headertext="zone1" runat="server">
        <zonetemplate>
          <wp:RowProviderWebPart Title="provider" ID="rp1" runat="server" />
          <wp:FieldConsumerWebPart Title="consumer" ID="fc1" runat="server" />
        </zonetemplate>
      </asp:webpartzone>
    </td>
    <td>
      <asp:connectionszone id="connectionszone1" runat="server" />
    </td>
  </tr>
  </table>

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

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

Supported in: 4.5.2, 4.5.1, 4.5, 4, 3.5, 3.0, 2.0

Windows 8.1, Windows Server 2012 R2, Windows 8, Windows Server 2012, Windows 7, Windows Vista SP2, Windows Server 2008 (Server Core Role not supported), Windows Server 2008 R2 (Server Core Role supported with SP1 or later; Itanium not supported)

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.

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