首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
您现在的位置: 程式碼之家 >> 編程語言 >  >> .NET 網頁程式設計 >> ASP.NET 基礎 >> 關於ASP.NET

ASP.NET 2.0 行動開發列表控制項完整比較:SelectionList、List、ObjectList 特性與適用場景

     編輯:關於ASP.NET

ASP.NET 2.0 行動控制項工具箱提供三種列表控制項:SelectionList、List、ObjectList,繼承自 MobileControl → ListControl → 各具特色。本文完整比較三者特性、呈現模式、分頁支援、多選能力與適用場景。

類別繼承關係

MobileControl
  └── ListControl (abstract)
        ├── SelectionList
        ├── List
        └── ObjectList

三大列表控制項詳細比較

特性SelectionListListObjectList
主要用途單選/多選/下拉選單表單輸入唯讀項目清單呈現資料繫結清單,支援排序/篩選/編輯/命令
呈現模式 (SelectType)ListBox(清單)、DropDown(下拉)、MultiSelectListBox(多選)、Radio(單選鈕)、CheckBox(核取方塊)ListBox(項目符號)、Numbered(編號)ListBox、DropDown、Table(表格)、Details(明細)
多選支援✅ 唯一支援多選❌ 單選❌ 單選(但可透過命令實現批次操作)
分頁支援❌ 無✅ ItemsPerPage、PagerStyle✅ 內建分頁、PageSize、PagerStyle
資料繫結DataSource/DataSourceID、DataTextField/DataValueField同 SelectionListDataSourceID、自動產生欄位、AutoGenerateFields、TableFields/DetailFields
命令事件❌❌✅ ItemCommand、SelectedIndexChanged、SortCommand
模板支援❌❌✅ ItemTemplate、HeaderTemplate、FooterTemplate、PagerTemplate
裝置相容性WML 瀏覽器可能不支援 DropDown,需 DeviceSpecific 切換廣泛支援需較佳裝置能力(HTML 3.2+)

SelectionList 詳細應用

單選下拉選單(性別選擇)

<mobile:SelectionList ID="selGender" runat="server" SelectType="DropDown">
  <mobile:ListItem Text="男" Value="M" />
  <mobile:ListItem Text="女" Value="F" />
</mobile:SelectionList>

多選核取方塊(興趣選擇)

<mobile:SelectionList ID="selInterests" runat="server" SelectType="CheckBox" DataSourceID="sdsInterests"
    DataTextField="InterestName" DataValueField="InterestID">
</mobile:SelectionList>

取得多選值:selInterests.GetSelectedIndices() 回傳 int[],對應 Items[index].Value。

List 詳細應用

分頁編號清單

<mobile:List ID="lstNews" runat="server" DataSourceID="sdsNews" 
    DataTextField="Title" DataValueField="NewsID"
    ItemsPerPage="5" Decorate="Numbered">
  <PagerStyle NextPageText="下一頁" PreviousPageText="上一頁" />
</mobile:List>

ObjectList 詳細應用

資料繫結表格模式含排序/命令

<mobile:ObjectList ID="objProducts" runat="server" DataSourceID="sdsProducts"
    AutoGenerateFields="False" TableFields="ProductName,UnitPrice,UnitsInStock"
    ItemCommand="objProducts_ItemCommand">
  <TableFields>
    <mobile:ObjectListField DataField="ProductName" HeaderText="產品" />
    <mobile:ObjectListField DataField="UnitPrice" HeaderText="價格" DataFormatString="{0:C}" />
    <mobile:ObjectListCommand FieldName="Select" Text="詳情" CommandName="Detail" />
  </TableFields>
  <DetailFields>
    <mobile:ObjectListField DataField="ProductName" HeaderText="產品" />
    <mobile:ObjectListField DataField="Description" HeaderText="說明" />
  </DetailFields>
  <PagerStyle NextPageText="下頁" PreviousPageText="上頁" />
</mobile:ObjectList>

ItemCommand 事件處理

protected void objProducts_ItemCommand(object sender, ObjectListCommandEventArgs e)
{
    if (e.CommandName == "Detail")
    {
        string productId = objProducts.Items[e.ListItemIndex].Value;
        // 導向明細頁或設定詳細視圖
        objProducts.SelectedIndex = e.ListItemIndex;
    }
}

DeviceSpecific 裝置適配差異

圖示說明:Pocket IE 顯示 SelectionList DropDown 為下拉選單;OpenWave WML 瀏覽器不支援下拉,自動回退顯示單選鈕清單。開發者需透過 DeviceSpecific/Choice 針對不同裝置定義替代呈現。

選擇指南

  • 表單輸入、需多選 → SelectionList(唯一多選選項)。
  • 單純清單呈現、需分頁 → List(輕量、分頁內建)。
  • 資料驅動、需排序/篩選/編輯/命令/模板 → ObjectList(功能最完整)。
  • 裝置廣泛相容性優先 → SelectionList + DeviceSpecific 定義回退呈現。

三大列表控制項各司其職,配合裝置適配機制,構成 ASP.NET 2.0 行動應用資料呈現與輸入的核心工具組。

  1. 上一篇文章:
  2. 下一篇文章:
Copyright © 程式碼之家 All Rights Reserved