| <%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %> <%@ Register TagPrefix="mobile" Namespace="System.Web.UI.MobileControls" Assembly="System.Web.Mobile" %> <html xmlns="http://www.w3.org/1999/xhtml" > <body> <mobile:Form id="Form1" runat="server"> <mobile:Label ID="Label1" Runat="server">请选择想要购买的手器品牌</mobile:Label> <mobile:SelectionList ID="SelectionList1" Runat="server" SelectType="MultiSelectListBox" DataTextField="Manufacturer" DataValueField="Model"> </mobile:SelectionList> <mobile:Command ID="Command1" Runat="server" OnClick="HandleMultiSelection">提交选择</mobile:Command> </mobile:Form> <mobile:Form ID="Form2" Runat="server"> <mobile:Label ID="Label2" Runat="server">你选择的手机型号为:</mobile:Label> <mobile:TextView ID="TextView1" Runat="server">TextView</mobile:TextView> </mobile:Form> </body> </html> Default.aspx.cs: using System; using System.Collections; using System.ComponentModel; using System.Data; using System.Drawing; using System.Web; using System.Web.Mobile; using System.Web.SessionState; using System.Web.UI; using System.Web.UI.MobileControls; using System.Web.UI.WebControls; using System.Web.UI.HtmlControls; public partial class _Default : System.Web.UI.MobileControls.MobilePage { protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { ArrayList array = new ArrayList(); array.Add(new MobileTelephone("Dopoda", "P800")); array.Add(new MobileTelephone("Motorola", "A1200")); array.Add(new MobileTelephone("Nokia", "N70")); array.Add(new MobileTelephone("Samsung", "E638")); SelectionList1.DataSource = array; SelectionList1.DataBind(); } } protected void HandleMultiSelection(object sender, EventArgs e) { this.ActiveForm = Form2; // Get the list items collection. MobileListItemCollection colItems = SelectionList1.Items; String strDisplaytext = ""; foreach (MobileListItem item in colItems) { if (item.Selected) { strDisplaytext += (item.Text + item.Value + "<br/>"); } } TextView1.Text = strDisplaytext; } } Mobile.cs: using System; using System.Data; using System.Configuration; using System.Web; using System.Web.Security; using System.Web.UI; using System.Web.UI.WebControls; using System.Web.UI.WebControls.WebParts; using System.Web.UI.HtmlControls; /// <summary> /// TeamStats 的摘要说明 /// </summary> public class MobileTelephone { private String manufacturer, model; public MobileTelephone(String manufacturer, String model) { this.manufacturer = manufacturer; this.model = model; } public String Manufacturer { get { return this.manufacturer; } } public String Model { get { return this.model; } } } |
![]() ![]() ![]() ![]() ![]() |
关注此文的读者还看过: