SelectionList 控制項基本上會提供清單的 UI 選取功能。雖然它們都是清單,SelectionList 控制項在功能和範圍方面與 List 控制項有所不同。您要選擇使用 SelectionList,或是選擇 List 控制項,取決於下列準則:
- 您是否打算包含 Command 控制項以便送出表單至伺服器?從 SelectionList 控制項選取的選擇不會產生伺服器事件。
- 您是否打算維護一或多個選取的項目?SelectionList 控制項允許選取多個項目。
- 您是否打算只呈現小型清單?您是否打算不支援裝置樣板,或者內部或自訂重新編頁?SelectionList 控制項只管理小型清單,並且不提供重新編頁。
- 您是否想要使用下拉式清單 (Drop-Down List) 或下拉式方塊?SelectionList 控制項支援這些功能。
如需斟酌 List 控制項來選擇 SelectionList 控制項的詳細資訊,請參閱 SelectionList 類別。
行動控制項語法
需要的屬性和具程式碼功能的項目以粗體樣式標註。
<mobile:SelectionListrunat="server"
id="id"
Font-Name="fontName"
Font-Size="{NotSet|Normal|Small|Large}"
Font-Bold="{NotSet|False|True}"
Font-Italic=""{NotSet|False|True}"
ForeColor="foregroundColor"
BackColor="backgroundColor"
Alignment="{NotSet|Left|Center|Right}"
StyleReference="styleReference"
Wrapping="{NotSet|Wrap|NoWrap}"
DataMember="dataMember"
DataTextField="DataTextField"
DataValueField="DataValueField"
OnItemDataBind="itemDataBindHandler"
OnSelectedIndexChanged="selectedIndexChangedHandler"
Rows="rows"
SelectType="{DropDown|ListBox|Radio|MultiSelectListBox|CheckBox}"
Title="Text">
Place DeviceSpecific/Choice construct here. (optional)
<Choice Add choice here>
</Choice>
</DeviceSpecific>
<Choice Add choice here>
</Choice>
</DeviceSpecific>
Place statically declared list items here. (optional)
<Item Text="Text" Value="Value" />
</mobile:SelectionList>
內含項目規則
下列控制項可以包含 SelectionList 控制項。
| 控制項 | 註解 |
|---|---|
| System.Web.UI.MobileControls.Form | 可以包含任何數目的 SelectionList 控制項。 |
| System.Web.UI.MobileControls.Panel | 可以包含任何數目的 SelectionList 控制項。 |
SelectionList 控制項可以包含下列控制項。
| 控制項 | 註解 |
|---|---|
| System.Web.UI.MobileControls.Item | 任何數目的 Item 控制項都可以包含在 SelectionList 控制項中。 |
裝置樣板
SelectionList 控制項不支援裝置樣板。
裝置的特定行為
| 裝置語言 | 行為描述 |
|---|---|
| HTML | SelectionList 控制項可呈現為下拉式方塊、清單方塊、選項按鈕群組或核取方塊群組,端視 SelectType 控制項而定。
Title 屬性 (Property) 會被忽略。 |
| WML | SelectionList 控制項將呈現為 <select> 建構,可以讓使用者使用數字鍵來按一下或選取項目。Card 的其他 UI 項目並沒有合併到這個選擇區塊。
會顯示 Title 屬性 (Property) 的文字。 |
SelectionList 控制項範例
下列範例顯示如何為立體聲元件建立選擇清單。當使用者選擇元件時,第二頁會顯示元件名稱與其價格。
<%@ Page Inherits="System.Web.UI.MobileControls.MobilePage"
Language="VB" %>
<%@ Register TagPrefix="mobile"
Namespace="System.Web.UI.MobileControls"
Assembly="System.Web.Mobile" %>
<script language="vb" runat="server">
Public Sub PriceHandler(source As Object, e As EventArgs)
Dim selectedStereoComponent As String
selectedStereoComponent = StereoComponents.Selection.Value
Price.Text = StereoComponents.Selection.Text _
+ " at " + selectedStereoComponent
ActiveForm = PricePage
End Sub
</script>
<mobile:Form runat="server">
<mobile:Label>For pricing, select a component:</mobile:Label><br><br>
<mobile:SelectionList id="StereoComponents" runat="server">
<item Text="Amplifier" Value="$500.00"/>
<item Text="Compact Disc" Value="$600.00"/>
<item Text="Receiver" Value="$1000.00"/>
<item Text="Speakers" Value="$800.00"/><br>
</mobile:SelectionList>
<mobile:Command runat="server" OnClick="PriceHandler">
Get the price!</mobile:Command>
</mobile:Form>
<mobile:Form runat="server" id="PricePage">
<mobile:Label runat="server" id="PriceMessage" />
Stereo Component Price Request</mobile:Label><br>
<mobile:Label runat="server" id="Price" />
</mobile:Form>
[C#]
<%@ Page Inherits="System.Web.UI.MobileControls.MobilePage"
Language="c#" %>
<%@ Register TagPrefix="mobile"
Namespace="System.Web.UI.MobileControls"
Assembly="System.Web.Mobile" %>
<script language="c#" runat="server">
public void PriceHandler(Object source, EventArgs e)
{
String selectedStereoComponent = StereoComponents.Selection.Value;
Price.Text = StereoComponents.Selection.Text
+ " at " + selectedStereoComponent;
ActiveForm = PricePage;
}
</script>
<mobile:Form runat="server">
<mobile:Label>For pricing, select a component:</mobile:Label><br><br>
<mobile:SelectionList id="StereoComponents" runat="server">
<item Text="Amplifier" Value="$500.00"/>
<item Text="Compact Disc" Value="$600.00"/>
<item Text="Receiver" Value="$1000.00"/>
<item Text="Speakers" Value="$800.00"/><br>
</mobile:SelectionList>
<mobile:Command runat="server" OnClick="PriceHandler">
Get the price!</mobile:Command>
</mobile:Form>
<mobile:Form runat="server" id="PricePage">
<mobile:Label runat="server" id="PriceMessage" />
Stereo Component Price Request</mobile:Label><br>
<mobile:Label runat="server" id="Price" />
</mobile:Form>