ObjectList.AutoGenerateFields 属性

定义

指定字段是否必须自动由数据生成。 启用后,数据的每个公共属性都成为控件的一个字段。 默认值是 true。 此 API 已废弃不用。 有关如何开发 ASP.NET 移动应用程序的信息,请参阅 移动应用 & 具有 ASP.NET 的网站

public:
 property bool AutoGenerateFields { bool get(); void set(bool value); };
[System.ComponentModel.Bindable(false)]
[System.ComponentModel.Browsable(true)]
public bool AutoGenerateFields { get; set; }
[<System.ComponentModel.Bindable(false)>]
[<System.ComponentModel.Browsable(true)>]
member this.AutoGenerateFields : bool with get, set
Public Property AutoGenerateFields As Boolean

属性值

如果自动从数据生成字段,则为 true;否则为 false

属性

示例

下面的代码示例演示如何使用 AutoGenerateFields 属性在控件的“详细信息”视图中 ObjectList 静态地将字段与其集合相关联。

注意

下面的代码示例使用单文件代码模型,如果直接复制到代码隐藏文件中,可能无法正常工作。 必须将此代码示例复制到扩展名为 .aspx 的空文本文件中。 有关详细信息,请参阅 ASP.NET Web 窗体页代码模型

<%@ Page Language="C#" 
    Inherits="System.Web.UI.MobileControls.MobilePage" %>
<%@ Register TagPrefix="mobile" 
    Namespace="System.Web.UI.MobileControls" 
    Assembly="System.Web.Mobile" %>

<script runat="server">
    public void Page_Load(Object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            // Create and fill the array.
            ArrayList arr = new ArrayList();
            arr.Add(new Task("Tomorrow's work", "Yes"));
            arr.Add(new Task("Today's work", "Yes"));
            arr.Add(new Task("Next week's work", "No"));

            // Associate the array to List1.
            List1.DataSource = arr;

            // Turn off automatic field generation
            // because fields were built by hand
            List1.AutoGenerateFields = false;
            List1.DataBind();
        }
    }

    private class Task
    {
        private string _TaskName;
        private string _Editable;
        public Task(string TaskName, string Editable)
        {
            _TaskName = TaskName;
            _Editable = Editable;
        }
        public string TaskName
        { get { return _TaskName; } }
        public string Editable
        { get { return _Editable; } }
    }
</script>

<html xmlns="http://www.w3.org/1999/xhtml" >
<body>
    <mobile:Form runat="server" id="Form1">
        <mobile:ObjectList runat="server" id="List1" >
            <!-- Build the fields -->
            <Field Name="Task Name" DataField="TaskName" 
                Title="Name of Task" />
            <Field Name="Editable?" DataField="Editable" 
                Title="Is Editable?" />
        </mobile:ObjectList>
    </mobile:Form>
</body>
</html>
<%@ Page Language="VB" 
    Inherits="System.Web.UI.MobileControls.MobilePage" %>
<%@ Register TagPrefix="mobile" 
    Namespace="System.Web.UI.MobileControls" 
    Assembly="System.Web.Mobile" %>

<script runat="server">
    Public Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs)
        If Not IsPostBack Then
            ' Create and fill the array.
            Dim arr As New ArrayList()
            arr.Add(New Task("Tomorrow's work", "Yes"))
            arr.Add(New Task("Today's work", "Yes"))
            arr.Add(New Task("Next week's work", "No"))

            ' Associate the array to List1.
            List1.DataSource = arr

            ' Turn off automatic field generation
            ' because fields were built by hand
            List1.AutoGenerateFields = False
            List1.DataBind()
        End If
    End Sub

    Private Class Task
        Private _TaskName As String
        Private _Editable As String
        Public Sub New(ByVal TaskName As String, ByVal Editable As String)
            _TaskName = TaskName
            _Editable = Editable
        End Sub
        Public ReadOnly Property TaskName() As String
            Get
                Return _TaskName
            End Get
        End Property
        Public ReadOnly Property Editable() As String
            Get
                Return _Editable
            End Get
        End Property
    End Class
</script>

<html xmlns="http://www.w3.org/1999/xhtml" >
<body>
    <mobile:Form runat="server" id="Form1">
        <mobile:ObjectList runat="server" id="List1" >
            <!-- Build the fields -->
            <Field Name="Task Name" DataField="TaskName" 
                Title="Name of Task" />
            <Field Name="Editable?" DataField="Editable" 
                Title="Is Editable?" />
        </mobile:ObjectList>
    </mobile:Form>
</body>
</html>

注解

当 为 时 true,对象列表处理集合中的 ObjectListFieldCollection 字段顺序。 在 时 false,必须指定字段的顺序,并将 属性设置为 DataItem 绑定到数据源。

适用于

另请参阅