ASP.NET 移动控件--SelectionList 控件
SelectionList 控件主要为列表提供用户界面选择功能。虽然它们都是列表,但 SelectionList 控件和 List 控件在功能和范围方面有所不同。选择使用 SelectionList 还是 List 控件取决于以下标准:
您是否要包括一个 Command 控件用于向服务器提交窗体?从 SelectionList 控件中选择的选项不生成服务器事件。
您是否要维护一个或多个所选的项?SelectionList 控件允许选择多个项。
您是否只想呈现一个较小的列表?您是否不想支持设备模板,或者内部或自定义分页?SelectionList 控件只能管理较小的列表,不提供分页功能。
您是否要使用下拉列表或组合框?SelectionList 控件支持这些功能。
有关选择 SelectionList 控件与 List 控件的更多详细信息,请参见 SelectionList 类。
移动控件语法
必需的属性、默认值和具有代码特征的元素以粗体显示。
<mobile:SelectionList
runat="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 SelectionList 控件可以包含任意数目的 Item 控件。
设备模板
SelectionList 控件不支持设备模板。
特定于设备的行为
设备语言 行为描述
HTML 根据 SelectType 控件,SelectionList 控件可以呈现为组合框、列表框、一组单选按钮或一组复选框。
忽略 Title 属性。
WML SelectionList 控件呈现为 <select> 构造,允许用户使用数字键单击或选择项。卡片上的其他用户界面元素不能合并到此 select 块中。
显示 Title 属性中的文本。
SelectionList 控件示例
下面的示例说明如何创建立体声部件的选择列表。当用户选择一个部件时,另一页显示部件名称及其价格。
[Visual Basic]
<%@ 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>

