Compartir a través de


ObjectList.AutoGenerateFields Propiedad

Definición

Especifica si los campos se deben generar automáticamente a partir de los datos. Cuando se habilita, cada propiedad pública de los datos pasa a ser un campo del control. El valor predeterminado es true. Esta API está obsoleta. Para obtener información sobre cómo desarrollar aplicaciones móviles ASP.NET, consulte Mobile Apps & 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

Valor de propiedad

Es true si los campos se generan automáticamente a partir de los datos; de lo contrario, es false.

Atributos

Ejemplos

En el ejemplo de código siguiente se muestra cómo usar la AutoGenerateFields propiedad para asociar estáticamente los campos a su colección en la vista Detalles de un ObjectList control.

Nota:

En el ejemplo de código siguiente se usa el modelo de código de un solo archivo y es posible que no funcione correctamente si se copia directamente en un archivo de código subyacente. Este ejemplo de código debe copiarse en un archivo de texto vacío que tenga una extensión .aspx. Para obtener más información, vea modelo de código de página de 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>

Comentarios

Cuando truees , la lista de objetos controla el orden de los campos de la ObjectListFieldCollection colección. Cuando false, debe especificar el orden de los campos y establecer la DataItem propiedad para enlazar a un origen de datos.

Se aplica a

Consulte también