This documentation is archived and is not being maintained.

AutoGeneratedField.DataType Property

Gets or sets the data type of the values displayed in an AutoGeneratedField object.

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

public Type DataType { get; set; }

Property Value

Type: System.Type
A Type that represents the data type of the value displayed in an AutoGeneratedField object. The default is String.

Use the DataType property to specify the data type of the values displayed in an AutoGeneratedField object. The data type determines what type of control is rendered in an AutoGeneratedField object to display the value. For example, a check box control is displayed when the type is Boolean.

The following example demonstrates how to use the DataType property to specify the data type of the field values when programmatically creating an AutoGeneratedField object in a custom control that derives from the DetailsView control.



using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Text;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Security.Permissions;
using System.Web;

namespace Samples.AspNet.CS.Controls
{

    [AspNetHostingPermission(SecurityAction.Demand, Level=AspNetHostingPermissionLevel.Minimal)]
    [AspNetHostingPermission(SecurityAction.InheritanceDemand, Level=AspNetHostingPermissionLevel.Minimal)]
    public class SimpleCustomControl : DetailsView
    {

        protected override AutoGeneratedField CreateAutoGeneratedRow(AutoGeneratedFieldProperties fieldProperties) 
        {

            // Create an AutoGeneratedField object.
            AutoGeneratedField field = new AutoGeneratedField(fieldProperties.DataField);

            // Set the properties of the AutoGeneratedField using
            // the values from the AutoGeneratedFieldProperties 
            // object contained in the fieldProperties parameter.
            ((IStateManager)field).TrackViewState();
            field.HeaderText = fieldProperties.Name;
            field.SortExpression = fieldProperties.Name;
            field.ReadOnly = fieldProperties.IsReadOnly;
            field.DataType = fieldProperties.Type;

            return field;
        }

    }
}



.NET Framework

Supported in: 4, 3.5, 3.0, 2.0

Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows XP SP2 x64 Edition, Windows Server 2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or later), Windows Server 2003 SP2

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