ObjectList.AutoGenerateFields プロパティ

定義

フィールドをデータから自動的に生成するかどうかを指定します。 有効にすると、データの各パブリック プロパティがコントロールのフィールドになります。 既定値は true です。 この API は、互換性のために残されています。 ASP.NET モバイル アプリケーションを開発する方法については、「ASP.NET を使用した Mobile Apps & サイト」を参照してください。

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 示します。

Note

次のコード サンプルでは、単一ファイルコード モデルを使用しており、分離コード ファイルに直接コピーすると正しく動作しない場合があります。 このコード サンプルは、拡張子が .aspx の空のテキスト ファイルにコピーする必要があります。 詳細については、「ASP.NET Web Forms ページ コード モデル」を参照してください。

<%@ 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 データ ソースにバインドするように設定する必要があります。

適用対象

こちらもご覧ください