ObjectList.AutoGenerateFields Właściwość

Definicja

Określa, czy pola muszą być generowane automatycznie na podstawie danych. Po włączeniu każdej właściwości publicznej danych staje się polem kontrolki. Wartość domyślna to true. Ten interfejs API jest nieaktualny. Aby uzyskać informacje na temat tworzenia ASP.NET aplikacji mobilnych, zobacz Mobile Apps & Sites with ASP.NET (Aplikacje mobilne & Sites with 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

Wartość właściwości

true jeśli pola są generowane automatycznie na podstawie danych; w przeciwnym razie , false.

Atrybuty

Przykłady

W poniższym przykładzie kodu pokazano, jak używać AutoGenerateFields właściwości do statycznego kojarzenia pól z ich kolekcją w widoku Szczegóły kontrolki ObjectList .

Uwaga

Poniższy przykładowy kod używa modelu kodu z jednym plikiem i może nie działać poprawnie, jeśli został skopiowany bezpośrednio do pliku za pomocą kodu. Ten przykładowy kod musi zostać skopiowany do pustego pliku tekstowego z rozszerzeniem aspx. Aby uzyskać więcej informacji, zobacz model kodu strony 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>

Uwagi

Gdy truelista obiektów obsługuje kolejność pól w kolekcji ObjectListFieldCollection . W przypadku falseelementu należy określić kolejność pól i ustawić DataItem właściwość, aby powiązać ze źródłem danych.

Dotyczy

Zobacz też