ObjectList.AutoGenerateFields 属性
定义
指定字段是否必须自动由数据生成。Specifies whether fields must be automatically generated from data. 启用后,数据的每个公共属性都成为控件的一个字段。When enabled, each public property of the data becomes a field of the control. 默认值是 true。The default value is true. 此 API 已废弃不用。This API is obsolete. 若要了解如何开发 ASP.NET 移动应用,请参阅 Mobile Apps & Sites with ASP.NET (ASP.NET 移动应用和网站)。For information about how to develop ASP.NET mobile applications, see 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
属性值
如果自动从数据生成字段,则为 true;否则为 false。true if the fields are automatically generated from data; otherwise, false.
- 属性
示例
下面的代码示例演示如何使用 AutoGenerateFields 属性在控件的详细信息视图中以静态方式将字段与其集合关联 ObjectList 。The following code example demonstrates how to use the AutoGenerateFields property to statically associate the fields with their collection in the Details view of an ObjectList control.
备注
下面的代码示例使用单文件代码模型,如果直接复制到代码隐藏文件中,则可能无法正常工作。The following code sample uses the single-file code model and may not work correctly if copied directly into a code-behind file. 必须将此代码示例复制到扩展名为 .aspx 的空文本文件中。This code sample must be copied into an empty text file that has an .aspx extension. 有关详细信息,请参阅 ASP.NET Web 窗体页代码模型。For more information, see ASP.NET Web Forms Page Code Model.
<%@ 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 。When true, the object list handles the fields order in the ObjectListFieldCollection collection. 如果为 false ,则必须指定字段的顺序,并将 DataItem 属性设置为绑定到数据源。When false, you must specify the order of the fields and set the DataItem property to bind to a data source.