共用方式為


List 控制項

呈現項目的清單至行動裝置。這個控制項透過裝置樣板集支援樣板化呈現,並且也支援內部重新編頁。如需詳細資訊,請參閱樣板集和樣板化控制項重新編頁文件。

靜態和互動模式

您可以設定此控制項在下列模式中執行:

  • 靜態模式 - 控制項表現像靜態清單一樣。靜態清單項目可以宣告為項目的子項目。
  • 互動模式 - 控制項會將項目呈現為互動項目。

這些模式的行為取決於事件處理常式是否存在。事件處理常式不存在時,控制項會設定為靜態模式。事件處理常式存在時,控制項會設定為互動模式,其中每一個項目都是會在按一下時產生事件的互動項目。

行動控制項語法

需要的屬性和具程式碼功能的項目以粗體樣式標註。

<mobile:Listrunat="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"
   Decoration="{None|Bulleted|Numbered}"
   ItemsAsLinks="{False|True}"
   ItemCount="itemCount"
   OnItemDataBind="onItemDataBindHandler"
   OnItemCommand="onItemCommandHandler"
   OnLoadItems="loadItemsHandler">

Place DeviceSpecific/Choice construct here. (optional)
   <DeviceSpecific>
      <Choice Add choice here>
      </Choice>
   </DeviceSpecific>

Place statically declared list items here. (optional)
   <Item Text="Text" Value="Value" />

</mobile:List>

內含項目規則

下列控制項可以包含 List 控制項。

控制項 註解
System.Web.UI.MobileControls.Form 可以包含任何數目的 List 控制項。
System.Web.UI.MobileControls.Panel 可以包含任何數目的 List 控制項。

List 控制項可以包含下列控制項。

控制項 註解
System.Web.UI.MobileControls.DeviceSpecific List 控制項中可以包含 0 或 1 個 DeviceSpecific 控制項。
System.Web.UI.MobileControls.Item 任何數目的 Item 控制項都可以包含在 Image 控制項中。

裝置樣板

樣板 說明
HeaderTemplate 頁首樣板會呈現在清單開頭。在重新編頁模式中,頁首會呈現在每一個網頁上。
FooterTemplate 頁尾樣板會呈現在清單結尾。在重新編頁模式中,頁尾會呈現在每一個網頁上。
ItemTemplate 項目樣板會針對每一個清單項目呈現。
AlternatingItemTemplate 如果有定義,交替項目樣板會取代偶數項目的項目樣板。例如,第二個項目是交替樣板,第四個項目同樣是,後續的每個偶數項目也都是這樣。
SeparatorTemplate 分隔符號樣板會呈現在兩個項目之間。

裝置的特定行為

裝置語言 行為描述
HTML HTML 呈現的清單會根據 Decoration 屬性 (Property) 中所設定的樣式:
  • 如果 Decoration 屬性 (Property) 的值設為 None,每一個項目即照原樣顯示 (沒有樣式)。
  • 如果 Decoration 屬性 (Property) 的值設為 Bulleted,項目則呈現為 <ul> 清單 (項目符號清單) 中的 <li> 項目 (清單項目)。
  • 如果 Decoration 屬性 (Property) 的值設為 Numbered,項目則呈現為 <ol> 清單 (編號清單) 中的 <li> 項目。

如果其中的 ItemCommand 事件已定義,項目文字會包含在超連結內。

藉由樣板化的控制項,控制項會依照樣板所唯一定義的方式來呈現清單。

WML 對於 WML 中的靜態清單,清單會呈現為連續的靜態行。

對於使用 Openwave 技術的裝置上的 WML 互動清單,清單會呈現為 <select> 建構,以便使用者使用數字鍵來按一下或選取項目。Card 上的其他 UI 項目都可以合併到這個選擇區塊中。

對於其他 WML 裝置上的互動清單,清單會呈現為一系列錨點。

藉由樣板化的控制項,控制項會依照樣板所唯一定義的方式來呈現清單。

範例

下列範例顯示水果的清單。當您選取水果時,控制項會顯示其價格。

<%@ 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">
protected Sub List_Click(source As Object, e As ListCommandEventArgs)
   Dim selectedFruit as String
   selectedFruit = "You selected " + e.ListItem.Text + _
      " at " + e.ListItem.Value + " per pound."
   PriceLabel.Text = selectedFruit
   ActiveForm = Price
End Sub
</script>

<mobile:Form id="ShowProduce" runat="server" BackColor="Green">
   <mobile:Label runat="server" id="label1">Pick a Fruit!</mobile:Label>
   <mobile:List runat="server" id="ListProduce" 
     OnItemCommand="List_Click" >
      <item Text="Apples" Value="20 cents" />
      <item Text="Apricots" Value="80 cents" />
      <item Text="Bananas" Value="79 cents" />
      <item Text="Grapes" Value="50 cents" />
      <item Text="Oranges" Value="30 cents" />
      <item Text="Peaches" Value="10 cents" /> 
      <item Text="Pears" Value="70 cents" />
      <item Text="Plums" Value="99 cents" />
   </mobile:List>
</mobile:Form>
<mobile:Form id="Price" runat = "server">
   <mobile:Label runat="server" id="PriceLabel"/>
</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">
protected void List_Click(Object source, ListCommandEventArgs e)
{
   String selectedFruit = "You selected " + e.ListItem.Text +
      " at " + e.ListItem.Value + " per pound.";
   PriceLabel.Text = selectedFruit;
   ActiveForm = Price;
}
</script>

<mobile:Form id="ShowProduce" runat="server" BackColor="Green">
   <mobile:Label runat="server" id="label1">Pick a Fruit!</mobile:Label>
   <mobile:List runat="server" id="ListProduce" 
     OnItemCommand="List_Click" >
      <item Text="Apples" Value="20 cents" />
      <item Text="Apricots" Value="80 cents" />
      <item Text="Bananas" Value="79 cents" />
      <item Text="Grapes" Value="50 cents" />
      <item Text="Oranges" Value="30 cents" />
      <item Text="Peaches" Value="10 cents" /> 
      <item Text="Pears" Value="70 cents" />
      <item Text="Plums" Value="99 cents" />
   </mobile:List>
</mobile:Form>
<mobile:Form id="Price" runat = "server">
   <mobile:Label runat="server" id="PriceLabel"/>
</mobile:Form>

請參閱

List 類別 | List 類別成員 | 控制項參考