首 页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开发教程
· WML语言基础(WAP建站...
· VS.NET 2003开发移动...
· [图文] ASP技术进行动态WAP...
· [图文] WML语言基础(WAP建站...
· asp.net移动控件开发...
· [图文] 创建移动Web应用程序...
相关文章
· [图文] ASP.NET移动开发之S...
· 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的开发...
wap中基于MobileControls.List的分页控件(c#)
作者:不详  来源:本站整理  发布时间:2006-9-13 22:35:23  发布人:tangyunfei

减小字体 增大字体


键字:
wap分页
list分页

简介:看到LIST在手机上显示的分页效果,我个人感觉特别不满,随手写了一个用户控件与大家分享,有补充之处请您修整留言.

用户控件ASPX代码:
 1<%@ Register TagPrefix="mobile" Namespace="System.Web.UI.MobileControls" Assembly="System.Web.Mobile" %>
 2<%@ Control Language="c#" AutoEventWireup="false" Codebehind="BestList.ascx.cs" Inherits="MERPWAP.BestList" TargetSchema="http://schemas.microsoft.com/Mobile/WebUserControl" %>
 3<mobile:list id="list" Decoration="Bulleted" runat="server"></mobile:list>
 4<mobile:Panel id="Panel1" runat="server" BreakAfter="True">
 5    <mobile:Label id="Label1" runat="server" BreakAfter="False">[</mobile:Label>
 6    <mobile:Label id="lbl_currpage" runat="server" BreakAfter="False">1</mobile:Label>
 7    <mobile:Label id="Label2" runat="server" BreakAfter="False">/</mobile:Label>
 8    <mobile:Label id="lbl_count" runat="server" BreakAfter="False">0</mobile:Label>
 9    <mobile:Label id="Label3" runat="server" BreakAfter="False">]  </mobile:Label>
10    <mobile:Label id="lbl_RoteCount" runat="server" BreakAfter="False">0</mobile:Label>
11    <mobile:Label id="Label5" runat="server" BreakAfter="False">条记录</mobile:Label>
12</mobile:Panel>
13<mobile:Panel id="Panel2" runat="server" BreakAfter="True">
14    <mobile:Command id="btn_first" runat="server" BreakAfter="False" Visible="False">[首页]</mobile:Command>
15    <mobile:command id="btn_syy" runat="server" BreakAfter="False" Visible="False">[上页]</mobile:command>
16    <mobile:command id="btn_xyy" runat="server" BreakAfter="False" Visible="False">[下页]</mobile:command>
17    <mobile:Command id="btn_end" runat="server" BreakAfter="False" Visible="False">[末页]</mobile:Command>
18</mobile:Panel>
19<mobile:Label id="lbl_index" runat="server" Visible="False">0</mobile:Label>

<%@ Register TagPrefix="mobile" Namespace="System.Web.UI.MobileControls" Assembly="System.Web.Mobile" %>
cs代码

namespace MERPWAP
{
    using System;
    using System.Data;
    using System.Drawing;
    using System.Web;
    using System.Web.Mobile;
    using System.Web.UI.MobileControls;
    using System.Web.UI.WebControls;
    using System.Web.UI.HtmlControls;

    public delegate void BestList_ItemCommand(object sender,System.Web.UI.MobileControls.ListCommandEventArgs e); 
    public delegate void BestList_PageIndexChange(object sender); 
    /**//// <summary>
    ///        BestList 的摘要说明。
    /// </summary>
    public abstract class BestList : System.Web.UI.MobileControls.MobileUserControl
    {
        protected System.Web.UI.MobileControls.Command btn_xyy;
        protected System.Web.UI.MobileControls.Command btn_syy;
        protected System.Web.UI.MobileControls.List list_dxk;
//        private static int  CurrPage=1,PageCount = 0;
        protected System.Web.UI.MobileControls.List list;
        protected System.Web.UI.MobileControls.Command btn_first;
        protected System.Web.UI.MobileControls.Command btn_end;
        protected System.Web.UI.MobileControls.Panel Panel1;
        protected System.Web.UI.MobileControls.Label lbl_currpage;
        protected System.Web.UI.MobileControls.Label lbl_count;
        protected System.Web.UI.MobileControls.Label Label1;
        protected System.Web.UI.MobileControls.Label Label2;
        protected System.Web.UI.MobileControls.Label Label3;
        protected System.Web.UI.MobileControls.Panel Panel2;
        protected System.Web.UI.MobileControls.Label lbl_RoteCount;
        protected System.Web.UI.MobileControls.Label Label5;
        protected System.Web.UI.MobileControls.Label lbl_index;

# region "变量及事件声明"
        private int MyPageSize =10;
        private DataTable MyDataSoune;
        public event BestList_ItemCommand BestListItemCommand; 
        public event BestList_PageIndexChange BestListPageIndexChange; 
#endregion

        private void Page_Load(object sender, System.EventArgs e)
        {
            //
            
        }

        Web 窗体设计器生成的代码#region Web 窗体设计器生成的代码
        override protected void OnInit(EventArgs e)
        {
            //
            // CODEGEN: 该调用是 ASP.NET Web 窗体设计器所必需的。
            //
            InitializeComponent();
            base.OnInit(e);
        }

        /**////        设计器支持所需的方法 - 不要使用
        ///        代码编辑器修改此方法的内容。
        /// </summary>
        private void InitializeComponent()
        {
            this.list.ItemCommand += new System.Web.UI.MobileControls.ListCommandEventHandler(this.list_ItemCommand);
            this.btn_first.Click += new System.EventHandler(this.btn_first_Click);
            this.btn_syy.Click += new System.EventHandler(this.btn_syy_Click);
            this.btn_xyy.Click += new System.EventHandler(this.btn_xyy_Click);
            this.btn_end.Click += new System.EventHandler(this.btn_end_Click);
            this.Load += new System.EventHandler(this.Page_Load);

        }
        #endregion

        /**//// <summary>
        /// 列表集合
        /// </summary>
        public System.Web.UI.MobileControls.MobileListItemCollection Items
        {
            get
            {
                return list.Items;
            }
        }
        /**//// <summary>
        /// 每页的记录数
        /// </summary>
        public int PageSize
        {
            get
            {
                return MyPageSize;
            }
            set 
            {
                MyPageSize=value;
            }
        }
        /**//// <summary>
        /// 当前索引号
        /// </summary>
        public int SelectIndex
        {
            get
            {
                if(lbl_index.Text != "")
                {
                    return Convert.ToInt32(lbl_index.Text);
                }
                else
                {
                    return -1;
                }
            }
            set
            {
                lbl_index.Text =Convert.ToString(value);
            }
        }
        /**//// <summary>
        /// 数据源表
        /// </summary>
        public DataTable DataSoune
        {
            get
            {
                return MyDataSoune;
            }
            set 
            {
                MyDataSoune=value;
            }
        }
        /**//// <summary>
        /// 列表文本数据字段
        /// </summary>
        public string DataTextField
        {
            get
            {
                return list.DataTextField ;
            }
            set 
            {
                list.DataTextField=value;
            }
        }
        /**//// <summary>
        /// 列表值数据字段
        /// </summary>
        public string DataValueField
        {
            get
            {
                return list.DataValueField  ;
            }
            set 
            {
                list.DataValueField=value;
            }
        }
        /**//// <summary>
        /// 页数
        /// </summary>
        public int PageCount
        {
            get
            {
                return Convert.ToInt32(lbl_count.Text.Trim());
            }
        }
/**//// <summary>
/// 列表框复位
/// </summary>
        public void ItemClear()
        {
            list.Items.Clear();
            list.DataSource =null;
            list.DataTextField="";
            list.DataValueField ="";
            lbl_index.Text ="0";
            lbl_currpage.Text ="1";
        }
        private void list_ItemCommand(object sender, System.Web.UI.MobileControls.ListCommandEventArgs e)
        {
            lbl_index.Text =e.ListItem.Index.ToString();
            if (BestListItemCommand !=null) BestListItemCommand(sender,e);
        } 
        /**//// <summary>
        /// 数据绑定
        /// </summary>
        public void DataBindList()
        {
            if(MyDataSoune != null)
            {
                //得出当前记录总数
                int RoteCount=MyDataSoune.Rows.Count;
                //当不同数据源绑定时恢复当前页为1(根据记录数判断是否是同一个数据源)
                int OldRoteCount = Convert.ToInt32(lbl_RoteCount.Text.Trim());
                if(OldRoteCount != 0 && OldRoteCount != RoteCount)
                {
                    lbl_currpage.Text = "1";
                }
                lbl_RoteCount.Text =RoteCount.ToString();
                //得出页总数
                if((RoteCount % PageSize) > 0)
                {
                    lbl_count.Text=Convert.ToString((int)(RoteCount / PageSize) + 1);
                }
                else
                {
                    lbl_count.Text=Convert.ToString(RoteCount / PageSize);
                }
                if(Convert.ToInt32(lbl_currpage.Text.Trim()) >0 && Convert.ToInt32(lbl_currpage.Text.Trim()) <= Convert.ToInt32(lbl_count.Text.Trim()))
                {
                    //据当前页求出本页的开始记录和结束记录索引
                    int start,end;
                    start=(Convert.ToInt32(lbl_currpage.Text.Trim()) - 1) * PageSize ;
                    if(Convert.ToInt32(lbl_currpage.Text.Trim()) == Convert.ToInt32(lbl_count.Text.Trim()))
                    {
                        end = RoteCount - 1;
                    }
                    else
                    {
                        end =start + PageSize - 1;
                    }
                    list.Items.Clear();
                    for(int i = start;i <= end;i++)
                    {
                        //初始化列表框
                        MobileListItem MyList=new MobileListItem();
                        MyList.Value =MyDataSoune.Rows[i][list.DataValueField.Trim()].ToString();
                        MyList.Text =MyDataSoune.Rows[i][list.DataTextField.Trim()].ToString();
                        list.Items.Add(MyList);
                    }
                }
                //---------导航按钮控制
                if(Convert.ToInt32(lbl_count.Text.Trim()) <= 1)
                {
                    //当只有一页时或没有记录时
                    btn_first.Visible =false;
                    btn_syy.Visible =false;
                    btn_xyy.Visible =false;
                    btn_end.Visible =false;
                    Panel1.Visible =false;
                }
                else if(Convert.ToInt32(lbl_currpage.Text.Trim()) == 1)
                {
                    //当为第一页时
                    btn_first.Visible =false;
                    btn_syy.Visible =false;
                    btn_xyy.Visible =true;
                    btn_end.Visible =true;
                    Panel1.Visible =true;
                }
                else if(Convert.ToInt32(lbl_currpage.Text.Trim()) == Convert.ToInt32(lbl_count.Text.Trim()))
                {
                    //当为最后一页时
                    btn_first.Visible =true;
                    btn_syy.Visible =true;
                    btn_xyy.Visible =false;
                    btn_end.Visible =false;
                    Panel1.Visible =true;
                }
                else if(Convert.ToInt32(lbl_currpage.Text.Trim()) == 2)
                {
                    //当为第二页时
                    btn_first.Visible =true;
                    btn_syy.Visible =false;
                    btn_xyy.Visible =true;
                    btn_end.Visible =true;
                    Panel1.Visible =true;
                }
                else if(Convert.ToInt32(lbl_currpage.Text.Trim()) == Convert.ToInt32(lbl_count.Text.Trim()) - 1)
                {
                    //当为最后一页时
                    btn_first.Visible =true;
                    btn_syy.Visible =true;
                    btn_xyy.Visible =false;
                    btn_end.Visible =true;
                    Panel1.Visible =true;
                }
                else
                {
                    btn_first.Visible =true;
                    btn_syy.Visible =true;
                    btn_xyy.Visible =true;
                    btn_end.Visible =true;
                    Panel1.Visible =true;
                }
            }
        }
        private void MyPageIdexChange(string key)
        {
            switch(key)
            {
                case "first" :
                    if(Convert.ToInt32(lbl_count.Text.Trim()) > 0)
                        lbl_currpage.Text = "1";
                    break;
                case "top":
                    if(Convert.ToInt32(lbl_currpage.Text.Trim()) > 1)
   &nb