代表 List 或 SelectionList ASP.NET 行動控制項中的個別項目。
命名空間: System.Web.UI.MobileControls
組件: System.Web.Mobile (在 system.web.mobile.dll 中)
語法
'宣告
Public Class MobileListItem
Inherits TemplateContainer
Implements IStateManager
'用途
Dim instance As MobileListItem
public class MobileListItem : TemplateContainer, IStateManager
public ref class MobileListItem : public TemplateContainer, IStateManager
public class MobileListItem extends TemplateContainer implements IStateManager
public class MobileListItem extends TemplateContainer implements IStateManager
備註
雖然類別名稱為 MobileListItem,但項目名稱為 Item。在行動頁面上,您可以使用 <Item> 項目 (Element) 來宣告項目 (Item)。
範例
在下列程式碼中,示範了如何使用 SelectionList.Items 屬性的選取項目索引,透過 MobileListItemCollection 類別管理 MobileListItem 物件中的項目。
<%@ 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
Label1.Text = "Select an item"
' Create and fill an array list.
Dim listValues As New ArrayList()
listValues.Add("One")
listValues.Add("Two")
listValues.Add("Three")
' Bind the array to the list.
SelList1.DataSource = listValues
SelList1.DataBind()
' Set the SelectType.
SelList1.SelectType = ListSelectType.Radio
Else
If (SelList1.SelectedIndex > -1) Then
' To show the selection, use the Selection property.
Label1.Text = "Your selection is " & _
SelList1.Selection.Text
' Or, show the selection by using
' the MobileListItemCollection class.
' Get the index of the selected item
Dim idx As Integer = SelList1.SelectedIndex
Label2.Text = "You have selected " & _
SelList1.Items(idx).Text
' Insert a copy of the selected item
Dim mi As MobileListItem = SelList1.Selection
Label3.Text = "The index of your selection is " & _
mi.Index.ToString()
SelList1.Items.Insert(idx, _
New MobileListItem(mi.Text + " Copy"))
Else
Label1.Text = "No items selected"
End If
End If
End Sub
</script>
<html xmlns="http:'www.w3.org/1999/xhtml" >
<body>
<mobile:form id="form1" runat="server">
<mobile:Label id="Label1" runat="server"
Text="Show a list" />
<mobile:Label id="Label2" runat="server" />
<mobile:Label id="Label3" runat="server" />
<mobile:SelectionList runat="server"
id="SelList1" />
<mobile:Command id="Command1" runat="server"
Text=" OK " />
</mobile:form>
</body>
</html>
<%@ 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)
{
Label1.Text = "Select an item";
// Create and fill an array list.
ArrayList listValues = new ArrayList();
listValues.Add("One");
listValues.Add("Two");
listValues.Add("Three");
// Bind the array to the list.
SelList1.DataSource = listValues;
SelList1.DataBind();
// Set the SelectType.
SelList1.SelectType =
System.Web.UI.MobileControls.ListSelectType.Radio;
}
else
{
if (SelList1.SelectedIndex > -1)
{
// To show the selection, use the Selection property.
Label1.Text = "Your selection is " +
SelList1.Selection;
// Or, show the selection by using
// the MobileListItemCollection class.
// Get the index of the selected item
int idx = SelList1.SelectedIndex;
Label2.Text = "You have selected " +
SelList1.Items[idx].Text;
// Insert a copy of the selected item
MobileListItem mi = SelList1.Selection;
Label3.Text = "The index of your selection is " +
mi.Index.ToString();
SelList1.Items.Insert(idx,
new MobileListItem(mi.Text + " Copy"));
}
else
{
Label1.Text = "No items selected";
}
}
}
</script>
<html xmlns="http://www.w3.org/1999/xhtml" >
<body>
<mobile:form id="form1" runat="server">
<mobile:Label id="Label1" runat="server"
Text="Show a list" />
<mobile:Label id="Label2" runat="server" />
<mobile:Label id="Label3" runat="server" />
<mobile:SelectionList runat="server"
id="SelList1" />
<mobile:Command id="Command1" runat="server"
Text=" OK " />
</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.Panel
System.Web.UI.MobileControls.TemplateContainer
System.Web.UI.MobileControls.MobileListItem
System.Web.UI.MobileControls.ObjectListItem
執行緒安全
這個型別的所有公用靜態成員 (即 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
請參閱
參考
MobileListItem 成員
System.Web.UI.MobileControls 命名空間
List 類別