為可選取的項目清單提供幾種不同的視覺化表示。
命名空間: System.Web.UI.MobileControls
組件: System.Web.Mobile (在 system.web.mobile.dll 中)
語法
'宣告
<ValidationPropertyAttribute("Selection")> _
Public Class SelectionList
Inherits MobileControl
Implements IPostBackDataHandler
'用途
Dim instance As SelectionList
[ValidationPropertyAttribute("Selection")]
public class SelectionList : MobileControl, IPostBackDataHandler
[ValidationPropertyAttribute(L"Selection")]
public ref class SelectionList : public MobileControl, IPostBackDataHandler
/** @attribute ValidationPropertyAttribute("Selection") */
public class SelectionList extends MobileControl implements IPostBackDataHandler
ValidationPropertyAttribute("Selection")
public class SelectionList extends MobileControl implements IPostBackDataHandler
備註
SelectionList 類別會維護單一或多個選取項目的選取範圍。SelectionList 是直接衍生自 MobileControl 類別,而且沒有任何分頁處理屬性,例如 ItemWeight 屬性。
範例
在下列程式碼中,SelectionList 類別的 DataSource 屬性是在初始頁面載入時所建立的值陣列。您可以變更 SelectType 屬性的設定,以查看不同版本的 SelectionList。
注意事項 |
|---|
以下程式碼範例使用單一檔案程式碼模型,如果直接複製到程式碼後置 (Code-Behind) 檔案即可能無法作用。這個程式碼範例必須複製到副檔名為 .aspx 的空白文字檔。如需詳細資訊,請參閱 ASP.NET Web 網頁程式碼模型。 |
<%@ 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.SelectionList
執行緒安全
這個型別的所有公用靜態成員 (即 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
請參閱
參考
SelectionList 成員
System.Web.UI.MobileControls 命名空間
注意事項