ASP.NET移动开发之SelectionList控件4
点击次数:19 次 发布日期:2008-11-26 11:48:11 作者:源代码网
|
源代码网推荐 源代码网推荐 下面这个示例将创建一个简单的ArrayList集合,作为Selection列表控件的数据源。在代码后置文件中,我们创建了一个Mobile类,用来存取每个数据项。在Page_Load事件处理函数中,我们将创建好的Mobile对象添加到一个ArrayList集合中。而后,将Selection列表控件与该ArrayList集合绑定。最后通过一个foreach 语句迭代整个列表,并将各个数据项中的信息以一个字符串的形式显示在页面上。 源代码网推荐 源代码网推荐 Default.ASPx 源代码网推荐 源代码网推荐 <%@ 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; } } 源代码网推荐 源代码网推荐
做人要厚道,请注明转自酷网动力(www.ASPCOOL.COM)。
源代码网推荐 源代码网供稿. |

做人要厚道,请注明转自酷网动力(www.ASPCOOL.COM)。