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;
using System.Data.OleDb;

public partial class viewBook : System.Web.UI.MobileControls.MobilePage
{
    public int dxClass;
    public int curpage;
    protected void Page_Load(object sender, EventArgs e)
    {
        if (Request.QueryString["menuID"] != null)
        {
            dxClass = Int32.Parse(Request.QueryString["menuID"].ToString());
        }

        if (!this.IsPostBack)
        {
            this.Bind();
        }

    }

    //获取目录
    private DataSet getMenuDs(int menuID)
    {
        OleDbConnection con = new OleDbConnection(@"provider=microsoft.jet.oledb.4.0;data source=" + Server.MapPath("App_Data/dx.mdb"));
        con.Open();
        string strCmd = "select * from menu where from=" + menuID;
        OleDbDataAdapter da = new OleDbDataAdapter(strCmd, con);
        DataSet ds = new DataSet();
        da.Fill(ds);
        con.Close();
        return ds;
    }

    //数据绑定
    private void Bind()
    {
        this.List1.Items.Clear();

        DataSet menuDs = getMenuDs(dxClass);

        this.Label3.Text = Convert.ToString(menuDs.Tables[0].Rows.Count / 10 + 1);

        curpage = Int32.Parse(this.Label2.Text);//当前页

        //如果当前页是第一页,并且只有一页面,那么不显示按钮
        if (this.Label2.Text == this.Label3.Text&&this.Label2.Text=="1")
        {
            this.Command1.Visible = false;
            this.Command2.Visible = false;
        }
        else if (this.Label2.Text =="1")//如果当前页是第一页,上一页按钮不显示
        {
            this.Command1.Visible = false;
            this.Command2.Visible = true;
        }
        else if (this.Label2.Text == this.Label3.Text)//当前页是最后一页,那么下一页按钮不显示
        {
            this.Command1.Visible = true;
            this.Command2.Visible = false;
        }
        else
        {
            this.Command1.Visible = true;
            this.Command2.Visible = true;
        }

        if (Convert.ToInt32(this.Label2.Text)  == Convert.ToInt32(this.Label3.Text))
        {
            for (int i = (curpage - 1) * 10; i < menuDs.Tables[0].Rows.Count; i++)
            {
                string dxShort = menuDs.Tables[0].Rows[i]["menuName"].ToString();
                MobileListItem item = new MobileListItem(dxShort, "viewList.aspx?bookID=" + menuDs.Tables[0].Rows[i]["menuID"].ToString());
                this.List1.Items.Add(item);
            }
        }
        else
        {
            for (int i = (curpage - 1) * 10; i < curpage * 10 - 1; i++)
            {
                string dxShort = menuDs.Tables[0].Rows[i]["menuName"].ToString();
                MobileListItem item = new MobileListItem(dxShort, "viewList.aspx?bookID=" + menuDs.Tables[0].Rows[i]["menuID"].ToString());
                this.List1.Items.Add(item);
            }
        }


    }
    //上一页
    protected void Command1_Click(object sender, EventArgs e)
    {
        this.Label2.Text = Convert.ToString(Int32.Parse(this.Label2.Text) - 1);
        this.Bind();
    }
    //下一页
    protected void Command2_Click(object sender, EventArgs e)
    {
        this.Label2.Text = Convert.ToString(Int32.Parse(this.Label2.Text) + 1);
        this.Bind();
    }
}

1,格式

<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE html PUBLIC "-//WAPFORUM//DTD XHTML Mobile 1.1//EN" "http://www.openmobilealliance.org/tech/DTD/xhtml-mobile11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>document title</title>
</head>
<body>
</body>
</html>

 

拨打电话
<a href="wtai://wp/mc;13888888888">Call Me Now</a>

 

访问asp站点的时候会根据访问的设备,输出不同的内容,如果用IE访问就输出的是html,手机访问,输出就是WML。是什么让他这么智能化呢?关键之处就在配置文件的<browserCaps>节!

在webconfig中加上这个,他可以强制输出wml,还有其他的移动设置属性都在这。

<browserCaps>
            
<result type="System.Web.Mobile.MobileCapabilities, System.Web.Mobile, Version=1.0.5000.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"/>
            
<use var="HTTP_USER_AGENT"/>

            browser=Unknown
            version=0.0
            majorversion=0
            minorversion=0
            frames=false
            tables=false
            cookies=false
            backgroundsounds=false
            vbscript=false
            javascript=false
            javaapplets=false
            activexcontrols=false
            win16=false
            win32=false
            beta=false
            ak=false
            sk=false
            aol=false
            crawler=false
            cdf=false
            gold=false
            authenticodeupdate=false
            tagwriter=System.Web.UI.Html32TextWriter
            ecmascriptversion=0.0
            msdomversion=0.0
            w3cdomversion=0.0
            platform=Unknown
            css1=false
            css2=false
            xml=false

            mobileDeviceManufacturer = "Unknown"
            mobileDeviceModel = "Unknown"

            gatewayVersion = "None"
            gatewayMajorVersion = "0"
            gatewayMinorVersion = "0"

           preferredRenderingType = "wml11"
           preferredRenderingMime = "text/vnd.wap.wml"
           preferredImageMime = "image/vnd.wap.wbmp"

            defaultScreenCharactersWidth = "12"
            defaultScreenCharactersHeight = "6"
            defaultScreenPixelsWidth = "96"
            defaultScreenPixelsHeight = "72"
            defaultCharacterWidth = "8"
            defaultCharacterHeight = "12"
            screenBitDepth = "1"
            isColor = "false"
            inputType = "telephoneKeypad"

            numberOfSoftkeys = "0"
            maximumSoftkeyLabelLength = "5"

            canInitiateVoiceCall = "false"

            canSendMail = "true"
            hasBackButton = "true"
            rendersWmlDoAcceptsInline = "true"
            rendersWmlSelectsAsMenuCards = "true"
            rendersBreaksAfterWmlAnchor = "false"
            rendersBreaksAfterWmlInput = "false"
            rendersBreakBeforeWmlSelectAndInput = "true"
            requiresAttributeColonSubstitution = "true"
            requiresPhoneNumbersAsPlainText = "false"
            requiresUrlEncodedPostfieldValues = "false"
            requiredMetaTagNameValue = ""
            rendersBreaksAfterHtmlLists = "true"
            requiresUniqueHtmlCheckboxNames = "true"
            requiresUniqueHtmlInputNames = "true"
            requiresUniqueFilePathSuffix = "true"
            supportsCss = "false"
            hidesRightAlignedMultiselectScrollbars = "false"
            canRenderAfterInputOrSelectElement = "true"
            canRenderInputAndSelectElementsTogether = "true"
            canRenderOneventAndPrevElementsTogether = "true"
            canCombineFormsInDeck = "true"
            canRenderMixedSelects = "true"
            canRenderPostBackCards = "true"
            canRenderSetvarZeroWithMultiSelectionList = "true"
            supportsImageSubmit = "true"
            supportsSelectMultiple = "true"
            requiresHtmlAdaptiveErrorReporting = "false"
            requiresContentTypeMetaTag = "false"
            requiresDBCSCharacter = "false"
            requiresOutputOptimization = "false"
            supportsAccesskeyAttribute = "false"
            supportsInputIStyle = "false"
            supportsInputMode = "false"
            supportsIModeSymbols = "false"
            supportsJPhoneSymbols = "false"
            supportsJPhoneMultiMediaAttributes = "false"
            maximumRenderedPageSize = "2000"
            requiresSpecialViewStateEncoding = "false"
            requiresNoBreakInFormatting = "false"
            requiresLeadingPageBreak = "false"
            supportsQueryStringInFormAction = "true"
            supportsCacheControlMetaTag = "true"
            supportsUncheck = "true"
            canRenderEmptySelects = "true"
            supportsRedirectWithCookie = "true"
            supportsEmptyStringInCookieValue = "true"
            cachesAllResponsesWithExpires = "false"
            requiresNoSoftkeyLabels = "false"
            defaultSubmitButtonLimit = "1"
            
            supportsBold = "false"
            supportsItalic = "false"
            supportsFontSize = "false"
            supportsFontName = "false"
            supportsFontColor = "true"
            supportsBodyColor = "true"
            supportsDivAlign = "true"
            supportsDivNoWrap = "false"
            supportsCharacterEntityEncoding = "true"

            isMobileDevice="false"
</browserCaps> 

另外通过设置
         Page.Response.Expires = -1;
   Response.CacheControl 
= "Public";
可以取消移动设备缓存,并通过RedirectToMobilePage函数进行重定向。

 最后手机中的效果图。


本文转载:CSDN博客