將項目清單呈現為靜態顯示或互動式清單。
命名空間: System.Web.UI.MobileControls
組件: System.Web.Mobile (在 system.web.mobile.dll 中)
語法
'宣告
Public Class List
Inherits PagedControl
Implements INamingContainer, ITemplateable, IPostBackEventHandler
'用途
Dim instance As List
public class List : PagedControl, INamingContainer, ITemplateable, IPostBackEventHandler
public ref class List : public PagedControl, INamingContainer, ITemplateable, IPostBackEventHandler
public class List extends PagedControl implements INamingContainer, ITemplateable,
IPostBackEventHandler
public class List extends PagedControl implements INamingContainer, ITemplateable,
IPostBackEventHandler
備註
這個控制項使用裝置樣板集和內部分頁來支援樣板化的呈現。如需詳細資訊,請參閱 ASP.NET 裝置篩選概觀和重新編頁。
| 主題 | 位置 |
|---|---|
| 逐步解說:針對特定裝置自訂 ASP.NET Mobile Web 網頁 | 利用 ASP.NET 建置行動應用程式 |
| 逐步解說:針對特定裝置自訂 ASP.NET Mobile Web 網頁 | 使用 ASP.NET 建置行動應用程式 |
| Walkthrough: Customizing ASP.NET Mobile Web Pages for Specific Devices | Building Mobile Applications with ASP.NET |
範例
在下列程式碼中,示範了陣列如何繫結和填入 List。請注意,您可以用程式設計方式設定 List 物件的 DataTextField 和 DataValueField 屬性。
<%@ Page Language="VB"
Inherits="System.Web.UI.MobileControls.MobilePage" %>
<%@ Register TagPrefix="mobile"
Namespace="System.Web.UI.MobileControls"
Assembly="System.Web.Mobile" %>
<script runat="server">
' Persist across multiple postbacks.
Private Shared doneCount, schedCount, pendCount As Integer
Protected Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs)
If Not IsPostBack Then
' Set the DataMembers of the List
List1.DataValueField = "Status"
List1.DataTextField = "TaskName"
' Create an ArrayList of task data
Dim arr As ArrayList = New ArrayList()
arr.Add(New Task("Define transactions", "scheduled"))
arr.Add(New Task("Verify transactions", "scheduled"))
arr.Add(New Task("Check balance sheet", "scheduled"))
arr.Add(New Task("Compile balance sheet", "scheduled"))
arr.Add(New Task("Prepare report", "scheduled"))
arr.Add(New Task("Send report", "scheduled"))
' Bind the array to the list
List1.DataSource = arr
List1.DataBind()
Const spec As String = "Start: {0} tasks are done, {1} " & _
"tasks are scheduled, and {2} tasks are pending."
Label2.Text = String.Format(spec, doneCount, _
schedCount, pendCount)
List1.Decoration = ListDecoration.Bulleted
End If
End Sub
Private Sub Status_ItemCommand(ByVal sender As Object, _
ByVal e As ListCommandEventArgs)
Const spec As String = "You now have {0} tasks done, {1} " & _
"tasks scheduled, and {2} tasks pending."
' Move selection to next status toward 'done'
Select Case e.ListItem.Value
Case "scheduled"
schedCount -= 1
pendCount += 1
e.ListItem.Value = "pending"
Case "pending"
pendCount -= 1
doneCount += 1
e.ListItem.Value = "done"
End Select
' Show the status of the current task
Label1.Text = e.ListItem.Text & " is " & _
e.ListItem.Value
' Show current selection counts
Label2.Text = String.Format(spec, doneCount, _
schedCount, pendCount)
End Sub
Private Sub Status_DataBinding(ByVal sender As Object, _
ByVal e As ListDataBindEventArgs)
' Increment initial counts
Select Case e.ListItem.Value
Case "done"
doneCount += 1
Case "scheduled"
schedCount += 1
Case "pending"
pendCount += 1
End Select
End Sub
' Custom class for the ArrayList items
Private Class Task
Private _TaskName, _Status As String
Public Sub New(ByVal TaskName As String, _
ByVal Status As String)
_TaskName = TaskName
_Status = Status
End Sub
Public ReadOnly Property TaskName() As String
Get
Return _TaskName
End Get
End Property
Public ReadOnly Property Status() As String
Get
Return _Status
End Get
End Property
End Class
</script>
<html xmlns="http://www.w3.org/1999/xhtml" >
<body>
<mobile:form id="form1" runat="server">
<mobile:Label ID="Label3" Runat="server">
Click a task to change its status from
scheduled to pending or from pending to done:
</mobile:Label>
<mobile:List runat="server" id="List1"
OnItemCommand="Status_ItemCommand"
OnItemDataBind="Status_DataBinding" />
<mobile:Label runat="server" id="Label1"
ForeColor="green" Font-Italic="true" />
<mobile:Label id="Label2" runat="server" />
</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">
' Persist across multiple postbacks.
Private Shared doneCount, schedCount, pendCount As Integer
Protected Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs)
If Not IsPostBack Then
' Set the DataMembers of the List
List1.DataValueField = "Status"
List1.DataTextField = "TaskName"
' Create an ArrayList of task data
Dim arr As ArrayList = New ArrayList()
arr.Add(New Task("Define transactions", "scheduled"))
arr.Add(New Task("Verify transactions", "scheduled"))
arr.Add(New Task("Check balance sheet", "scheduled"))
arr.Add(New Task("Compile balance sheet", "scheduled"))
arr.Add(New Task("Prepare report", "scheduled"))
arr.Add(New Task("Send report", "scheduled"))
' Bind the array to the list
List1.DataSource = arr
List1.DataBind()
Const spec As String = "Start: {0} tasks are done, {1} " & _
"tasks are scheduled, and {2} tasks are pending."
Label2.Text = String.Format(spec, doneCount, _
schedCount, pendCount)
List1.Decoration = ListDecoration.Bulleted
End If
End Sub
Private Sub Status_DataBinding(ByVal sender As Object, _
ByVal e As ListDataBindEventArgs)
' Increment initial counts
Select Case e.ListItem.Value
Case "done"
doneCount += 1
Case "scheduled"
schedCount += 1
Case "pending"
pendCount += 1
End Select
End Sub
Private Sub Status_ItemCommand(ByVal sender As Object, _
ByVal e As ListCommandEventArgs)
Const spec As String = "You now have {0} tasks done, {1} " & _
"tasks scheduled, and {2} tasks pending."
' Move selection to next status toward 'done'
Select Case e.ListItem.Value
Case "scheduled"
schedCount -= 1
pendCount += 1
e.ListItem.Value = "pending"
Case "pending"
pendCount -= 1
doneCount += 1
e.ListItem.Value = "done"
End Select
' Show the status of the current task
Label1.Text = e.ListItem.Text & " is " & _
e.ListItem.Value
' Show current selection counts
Label2.Text = String.Format(spec, doneCount, _
schedCount, pendCount)
End Sub
' Custom class for the ArrayList items
Private Class Task
Private _TaskName, _Status As String
Public Sub New(ByVal TaskName As String, _
ByVal Status As String)
_TaskName = TaskName
_Status = Status
End Sub
Public ReadOnly Property TaskName() As String
Get
Return _TaskName
End Get
End Property
Public ReadOnly Property Status() As String
Get
Return _Status
End Get
End Property
End Class
</script>
<html xmlns="http://www.w3.org/1999/xhtml" >
<body>
<mobile:form id="form1" runat="server">
<mobile:Label ID="Label3" Runat="server">
Click a task to change its status from
scheduled to pending or from pending to done:
</mobile:Label>
<mobile:List runat="server" id="List1"
OnItemCommand="Status_ItemCommand"
OnItemDataBind="Status_DataBinding" />
<mobile:Label runat="server" id="Label1"
ForeColor="green" Font-Italic="true" />
<mobile:Label id="Label2" runat="server" />
</mobile:form>
</body>
</html>
.NET Framework 安全性
- AspNetHostingPermission 用於裝載環境中的作業。要求值:LinkDemand,權限值:Minimal。
- AspNetHostingPermission 用於裝載環境中的作業。要求值:InheritanceDemand,權限值:Minimal。
繼承階層架構
System.Object
System.Web.UI.Control
System.Web.UI.MobileControls.MobileControl
System.Web.UI.MobileControls.PagedControl
System.Web.UI.MobileControls.List
執行緒安全
這個型別的所有公用靜態成員 (即 Visual Basic 中的 Shared 成員) 都是安全執行緒。並非所有的執行個體成員均為安全執行緒。
平台
Windows 98、 Windows 2000 SP4、 Windows Millennium Edition、 Windows Server 2003、 Windows XP Media Center Edition、 Windows XP Professional x64 Edition、 Windows XP SP2、 Windows XP Starter Edition
.NET Framework 並不支援各種平台的所有版本。如需支援平台版本的相關資訊,請參閱系統需求一節的內容。
版本資訊
.NET Framework
支援版本:2.0、1.1
請參閱
參考
List 成員
System.Web.UI.MobileControls 命名空間
List 類別