ObjectList.AutoGenerateFields 屬性
定義
重要
部分資訊涉及發行前產品,在發行之前可能會有大幅修改。 Microsoft 對此處提供的資訊,不做任何明確或隱含的瑕疵擔保。
指定是否必須從資料自動產生欄位。 啟用時,資料的每個公用 (Public) 屬性會變成控制項的欄位。 預設值是 true
。 這個 API 已經過時。 如需如何開發 ASP.NET 行動應用程式的資訊,請參閱 具有 ASP.NET 的Mobile Apps & Sites。
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 網頁代碼模型。
<%@ 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 為系結至數據源。