ASP.NET移动开发之SelectionList控件(3)

识别Selection列表控件中被选中的数据项(多项模式)

  在Selection列表控件的多选模式下,你必须检测列表中的每个数据项,以便确定那些数据项处于选中的状态。前文提及过,我们可以使用Selection列表控件的Items属性来访问MobileListItemCollection对象。在该集合中,那些处于选中状态的MobileListItem对象,其Selected属性的属性值将为true。下面的程序清单就是用来指出列表中那些数据项处于选中的状态:

  Default.aspx:
+展开
-HTML
<%@ 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:
+展开
-C#
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;
}
}


http://hi.baidu.com/zhiwei%5F117/blog/item/4485a6f5e1b5a5e57609d728.html

加支付宝好友偷能量挖...


评论(0)网络
阅读(91)喜欢(0)Asp.Net/C#/WCF