AutoGeneratedFieldProperties.IsReadOnly 属性

定义

获取或设置一个值,该值指示是否可以以编辑模式修改 AutoGeneratedField 对象中显示的值。Gets or sets a value indicating whether the values displayed in an AutoGeneratedField object can be modified in edit mode.

public:
 property bool IsReadOnly { bool get(); void set(bool value); };
public bool IsReadOnly { get; set; }
member this.IsReadOnly : bool with get, set
Public Property IsReadOnly As Boolean

属性值

true 指明该值为只读;否则,为 falsetrue to indicate that the values are read-only; otherwise, false. 默认值为 falseThe default is false.

示例

下面的代码示例演示如何使用IsReadOnly属性来确定要用于设置AutoGeneratedField对象的ReadOnly属性的值。The following code example demonstrates how to use the IsReadOnly property to determine the value with which to set the ReadOnly property of an AutoGeneratedField object.


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;
        }
    }
}


Imports System.ComponentModel
Imports System.Web.UI
Imports System.Web.UI.WebControls
Imports System.Security.Permissions
Imports System.Web

Namespace Samples.AspNet.VB.Controls

    <AspNetHostingPermission(SecurityAction.Demand, Level:=AspNetHostingPermissionLevel.Minimal), AspNetHostingPermission(SecurityAction.InheritanceDemand, Level:=AspNetHostingPermissionLevel.Minimal)> Public Class SimpleCustomControl
        Inherits System.Web.UI.WebControls.DetailsView

        Protected Overrides Function CreateAutoGeneratedRow(ByVal fieldProperties As AutoGeneratedFieldProperties) As AutoGeneratedField

            ' Create an AutoGeneratedField object.
            Dim field As New AutoGeneratedField(fieldProperties.DataField)

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

            Return field

        End Function

    End Class

End Namespace

注解

使用属性来指定是否可以在编辑模式下修改绑定AutoGeneratedField到对象的字段的值。 IsReadOnlyUse the IsReadOnly property to specify whether the values of the field bound to an AutoGeneratedField object can be modified in edit mode. 当数据绑定控件处于编辑模式时, 只读字段将显示为纯文本, 而无需任何编辑控件。When a data-bound control is in edit mode, fields that are read-only are displayed as plain text, without any editing controls.

适用于

另请参阅