ASP.NET移动开发之SelectionList控件3
点击次数:26 次 发布日期:2008-11-26 11:48:14 作者:源代码网
|
源代码网推荐 源代码网推荐 在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; 源代码网推荐 } 源代码网推荐 } 源代码网推荐 源代码网推荐 下面的对应的截图: 源代码网推荐
做人要厚道,请注明转自酷网动力(www.ASPCOOL.COM)。
源代码网推荐 源代码网供稿. |

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