当前位置:首页 > 网络编程 > WEB编程 > ASP.net >  ASP.NET移动开发之SelectionList控件2

 ASP.NET移动开发之SelectionList控件2

点击次数:18 次 发布日期:2008-11-26 11:48:16 作者:源代码网
源代码网推荐      Selection列表控件的类型
源代码网推荐  
源代码网推荐    Selection列表控件允许用户只能做出单项的选择,当然这需要你将Selection列表控件的SelectType属性设置为DropDown、ListBox或Radio。如果你将Selection列表控件的SelectType属性设置为MultiSelectListBox 或CheckBox的话,用户将可以同时选择列表中的多个选项。在代码中,你可以使用SelectionList类中的SelectType方法来设置或获取列表控件所要使用的类型。如果Selection列表控件采用的是多项选择模式的话,那么IsMultiSelect属性将返回一个true值。
源代码网推荐  
源代码网推荐    注意,在WML 1.2或者以前的WML版本中,是无法支持单项框、下拉列表等图形用户界面元素的。在这些只上述的WML设备上,Selection列表控件是以一个WML<select>元素进行呈现的,<select>元素也支持单项和多项的方式。在WML浏览器上,你可以使用软键(softkey)定位到一个数据项上进行选择,也可以使用一个数字键选择一个数据项,很显然,使用数字键的方式更便捷也更直观。因此,如果你想采用数字键来选择列表中的数据项的话,那么你必须确保该列表的项数应该小于或等于9个。下图是Selection列表控件的不同类型在不同浏览器上的显示效果:
源代码网推荐  
源代码网推荐  构建一个静态列表
源代码网推荐  
源代码网推荐    在静态列表中,数据项是使用Text属性指定一个字符串来进行呈现的,而不是动态地读取自数据源中的某个字段内容。要指定一个静态列表的数据项,你必须使用<Item>属性,具体的示例代码如下:
源代码网推荐  
源代码网推荐  <Item Text="Text" Value="Value" Selected="{True|False}" />
源代码网推荐  
源代码网推荐    Text属性用来指定在列表中显示的数据项信息,而Value就是相关联的隐藏值。如果你希望某数据项在默认情况下就处于被选中的状态的话,那么你可以将Selected属性设置为True。
源代码网推荐  
源代码网推荐    注意,每个Selection列表控件都与一个MobileListItemCollection对象关联。当你使用服务器控件语法静态地定义数据项,实际上是将与每个数据项对应的MobileListItem对象添加到MobileListItemCollection对象中。你可以在代码中使用Items属性来访问MobileListItemCollection集合。你还可以使用MobileListItemCollection类中的Add、Clear和Remove等方法来添加、清除或删除数据项。这些方法的具体用法你可以参考相应的MSND帮助文档,这里就不再详细介绍了。
源代码网推荐  
源代码网推荐    识别Selection列表控件中被选中的数据项(单项模式)
源代码网推荐  
源代码网推荐    在Selection列表控件的单选模式下,你可以使用Selection.Name属性来获取被选中数据项的显示文本,还可以使用Selection.Value属性获取被选中数据项的对应的隐藏值。下面的两个程序清单就是一个显示被选中数据项对应隐藏值的示例代码:
源代码网推荐  
源代码网推荐    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">
源代码网推荐  <Item Text="Dopoda" Value="P800" />
源代码网推荐  <Item Text="Motorola" Value="A1200" />
源代码网推荐  <Item Text="Nokia" Value="N70" />
源代码网推荐  <Item Text="Samsung" Value="E638" />
源代码网推荐   </mobile:SelectionList>
源代码网推荐    <mobile:Command runat="server" id="Command1"
源代码网推荐  OnClick="HandleSingleSelection">提交选择</mobile:Command>
源代码网推荐  </mobile:Form>
源代码网推荐  <mobile:Form ID="Form2" Runat="server">
源代码网推荐  <mobile:Label runat="server" id="Label2">你选择的手机型号为:</mobile:Label>
源代码网推荐  <mobile:Label runat="server" id="Label3"/>
源代码网推荐  </mobile:Form>
源代码网推荐  </body>
源代码网推荐  </html>
源代码网推荐  
源代码网推荐    程序代码说明:在这个程序中,我们在该页面上创建了两个窗体,Form1上放置了一个SelectionList列表控件,默认的类型为下拉列表,所以你只可以选择一项。当然,你还可以显式地设置SelectType属性为"DropDown"。在代码中可以看到,我们使用<Item>元素静态地定义各个数据项,其中用Text属性设置列表控件要显式的字符信息,而Value属性就是与显示的字符信息相关联的隐藏值(本例中为手机的制造商和机型)。由于你选择一个数据项后,SelectionList列表控件无法自动将改变后的信息自动回发到服务器上,所以还在Form1上再放置了一个Command控件,用来产生一个回发。也就是说当用户选择好了列表中的某项后,在点击提交按钮就可以将相应的信息回发到服务器端进行处理了,我们在本例中设置了该Command控件OnClick事件的处理函数为HandleSingleSelection,该事件处理函数的具体内容你可以查看对应的代码后置文件。Form2的功能就是显示那个数据项被用户选中,当你点击提交按钮后,Form2窗体将作为活动窗体,显示信息。
源代码网推荐  
源代码网推荐    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 HandleSingleSelection(object sender, EventArgs e)
源代码网推荐  {
源代码网推荐  this.ActiveForm = Form2;
源代码网推荐  String selectedMobile = SelectionList1.Selection.Value;
源代码网推荐  Label3.Text = SelectionList1.Selection + selectedMobile;
源代码网推荐  }
源代码网推荐  }
源代码网推荐  
源代码网推荐    程序代码说明:HandleSingleSelection就是Command控件的OnClick事件的处理函数。一旦用户点击了该Command按钮,将使Form2成为活动窗体。并在Label3控件上将选中的数据项的字符信息和隐藏值显示出来。
源代码网推荐  
源代码网推荐    如果你不在移动Web.Config文件中设置如下的代码,则在Openwave浏览器中会出错:
源代码网推荐  
源代码网推荐  <sessionState mode="InProc" cookieless="true" timeout="20"></sessionState>
源代码网推荐  
源代码网推荐    为此你最好将如下的移动Web.Config配置代码替代Visual Studio自动生成的移动Web.Config配置代码:
源代码网推荐  
源代码网推荐    Web.Config
源代码网推荐  
源代码网推荐  <?XML version="1.0"?>
源代码网推荐  <!-- 注意: 除了手动编辑此文件以外,您还可以使用 Web 管理工具来
源代码网推荐  
源代码网推荐    配置应用程序的设置。可以使用 Visual Studio 中的"网站"->"ASP.NET 配置"选项。
源代码网推荐  
源代码网推荐    设置和注释的完整列表在machine.config.comments 中,该文件通常位于 WindowsMicrosoft.netFrameworkv2.0.xxxxxConfig 中
源代码网推荐  -->
源代码网推荐  <configuration>
源代码网推荐  <appSettings/>
源代码网推荐  <connectionStrings/>
源代码网推荐  <system.web>
源代码网推荐  <!--
源代码网推荐  设置 compilation debug="true" 将调试符号插入已编译的页面中。
源代码网推荐  但由于这会影响性能,因此只在开发过程中将此值设置为 true。
源代码网推荐  -->
源代码网推荐  <compilation debug="true"/>
源代码网推荐  <!--
源代码网推荐  通过 <authentication> 节可以配置 ASP.NET 使用的
源代码网推荐  安全身份验证模式,以标识传入的用户。
源代码网推荐  -->
源代码网推荐  <authentication mode="Windows"/>
源代码网推荐  <!--
源代码网推荐  如果在执行请求的过程中出现未处理的错误,则通过 <customErrors> 节
源代码网推荐  可以配置相应的处理步骤。具体说来,开发人员通过该节可以
源代码网推荐  配置要显示的 html 错误页以代替错误堆栈跟踪。
源代码网推荐  -->
源代码网推荐  <customErrors mode="RemoteOnly" defaultRedirect="GenericErrorPage.htm">
源代码网推荐  <!--
源代码网推荐  <error statusCode="403" redirect="NoAccess.htm" />
源代码网推荐  <error statusCode="404" redirect="FileNotFound.htm" />
源代码网推荐  -->
源代码网推荐  </customErrors>
源代码网推荐  <!--
源代码网推荐  完全限定客户端重定向的 URL
源代码网推荐  有些移动设备要求对客户端重定向的 URL 进行完全限定。
源代码网推荐  -->
源代码网推荐  <httpRuntime useFullyQualifiedRedirectUrl="true"/>
源代码网推荐  <!--
源代码网推荐  指定无 Cookie 的数据字典类型
源代码网推荐  这将使字典内容出现在本地请求 url 查询字符串中。
源代码网推荐  这是在无 Cookie 的设备上进行 Forms 身份验证所必需的。
源代码网推荐  -->
源代码网推荐  <mobileControls cookielessDataDictionaryType="System.Web.Mobile.CookielessData"/>
源代码网推荐  
源代码网推荐  <sessionState mode="InProc" cookieless="true" timeout="20"></sessionState>
源代码网推荐  
源代码网推荐  <deviceFilters>
源代码网推荐  <filter name="isJPhone" compare="Type" argument="J-Phone"/>
源代码网推荐  <filter name="isHTML32" compare="PreferredRenderingType" argument="html32"/>
源代码网推荐  <filter name="isWML11" compare="PreferredRenderingType" argument="wml11"/>
源代码网推荐  <filter name="isCHTML10" compare="PreferredRenderingType" argument="chtml10"/>
源代码网推荐  <filter name="isGoAmerica" compare="Browser" argument="Go.Web"/>
源代码网推荐  <filter name="isMME" compare="Browser" argument="Microsoft Mobile Explorer"/>
源代码网推荐  <filter name="isMyPalm" compare="Browser" argument="MyPalm"/>
源代码网推荐  <filter name="isPocketIE" compare="Browser" argument="Pocket IE"/>
源代码网推荐  <filter name="isUP3x" compare="Type" argument="Phone.com 3.x Browser"/>
源代码网推荐  <filter name="isUP4x" compare="Type" argument="Phone.com 4.x Browser"/>
源代码网推荐  <filter name="isEricssonR380" compare="Type" argument="Ericsson R380"/>
源代码网推荐  <filter name="isNokia7110" compare="Type" argument="Nokia 7110"/>
源代码网推荐  <filter name="prefersGIF" compare="PreferredImageMIME" argument="image/gif"/>
源代码网推荐  <filter name="prefersWBMP" compare="PreferredImageMIME" argument="image/vnd.wap.wbmp"/>
源代码网推荐  <filter name="supportsColor" compare="IsColor" argument="true"/>
源代码网推荐  <filter name="supportsCookies" compare="Cookies" argument="true"/>
源代码网推荐  <filter name="supportsJavaScript" compare="Javascript" argument="true"/>
源代码网推荐  <filter name="supportsVoiceCalls" compare="CanInitiateVoiceCall" argument="true"/>
源代码网推荐  </deviceFilters>
源代码网推荐  </system.web>
源代码网推荐  </configuration>
源代码网推荐  
源代码网推荐    下面的是Pocket IE和Openwave浏览器在运行该程序时的截图:
源代码网推荐  
源代码网推荐    做人要厚道,请注明转自酷网动力(www.ASPCOOL.COM)。
源代码网推荐


源代码网供稿.
网友评论 (0)
会员中心
网络编程
本站推荐
网络编程之精华