|
|
| ASP.NET移动开发之SelectionList控件 |
| 作者:不详 来源:本站整理 发布时间:2007-5-13 18:23:11 发布人:tangyunfei |
减小字体
增大字体
下面的是Pocket IE和Openwave浏览器在运行该程序时的截图:
识别Selection列表控件中被选中的数据项(多项模式)
在Selection列表控件的多选模式下,你必须检测列表中的每个数据项,以便确定那些数据项处于选中的状态。前文提及过,我们可以使用Selection列表控件的Items属性来访问MobileListItemCollection对象。在该集合中,那些处于选中状态的MobileListItem对象,其Selected属性的属性值将为true。下面的程序清单就是用来指出列表中那些数据项处于选中的状态:
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"> <Item Text="Dopoda" Value="P800" /> <Item Text="Motorola" Value="A1200" /> <Item Text="Nokia" Value="N70" /> <Item Text="Samsung" Value="E638" /> </mobile:SelectionList> <mobile:Command ID="Command1" Runat="server" OnClick="HandleMultiTeamSelection">提交选择</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> | 程序代码说明:由于我们要在这个列表控件中实现多选,为此将Selection列表控件的SelectType设置为MultiSelectListBox。而后在Form2控件中添加一个TextView控件,使得所有被选中的数据项的字符信息和隐藏值信息都可以显示出来。
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 HandleMultiTeamSelection(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; } } | 下面的对应的截图:
| ∷相关文章评论∷ (评论内容只代表网友观点,与本站立场无关!) [更多评论...] |
|
|
|
|
|
-
-
-
-
-
-
Copyright © 2002-2005 wapkf.com. All Rights Reserved . 浙ICP备06013604号|站长QQ:274273595
|
|
|