首 页WAP教程WAP源码WAP电子书客户留言龙腾电脑维修网158网络电视本站论坛繁體中文
设为首页
加入收藏
联系我们
您当前的位置:WAP开发网 -> WAP教程 -> ASP.net WAP开发教程 -> 文章内容 退出登录 用户管理
栏目导航
· ASP WAP开发教程 · ASP.net WAP开发教程
· PHP WAP开发教程 · WML教程
· JSP开发WAP教程 · WAP 2.0
· 综合杂谈
热门文章
· WAP 2.0教程
· WML语言基础(WAP建站...
· 用VS2005实现ASP.NE...
· [组图] php WAp开发教程
· [图文] ASP技术进行动态WAP...
· WML语言基础(WAP建站...
· VS.NET 2003开发移动...
· JSP开发WAP技术
· asp.net移动控件开发...
· [图文] WML语言基础(WAP建站...
相关文章
· [图文] ASP.NET 2.0 WAP开发...
· ASP.NET 2.0移动开发...
· ASP.NET 移动 Web 窗...
· asp.net移动控件开发...
· ASP.NET 2.0移动开发...
· Wap页面使用asp.net...
· ASP.NET 2.0移动开发...
· ASP.NET 2.0移动开发...
· asp.net2.0移动控件...
· asp.net对wap的开发...
ASP.NET移动开发之SelectionList控件
作者:不详  来源:本站整理  发布时间:2007-5-13 18:23:11  发布人:tangyunfei

减小字体 增大字体




  识别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 中,该文件通常位于 \Windows\Microsoft.NET\Framework\v2.0.xxxxx\Config 中
-->
<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>

上一页  [1] [2] [3] [4]  下一页

[] [返回上一页] [打 印] [收 藏]
∷相关文章评论∷    (评论内容只代表网友观点,与本站立场无关!) [更多评论...]
关于本站 - 网站帮助 - 广告合作 - 下载声明 - 友情连接 - 网站地图 - 管理登录
Copyright © 2002-2005 wapkf.com. All Rights Reserved .
浙ICP备06013604号|站长QQ:274273595