AutoGeneratedField.DataType Property

 
System_CAPS_noteNote

The .NET API Reference documentation has a new home. Visit the .NET API Browser on docs.microsoft.com to see the new experience.

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
Available since 2.0
Return to top
Show: