首 页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文本分页控件(VB版)
作者:不详  来源:本站整理  发布时间:2006-9-13 22:32:56  发布人:tangyunfei

减小字体 增大字体


用户控件源码 BestTextView.ascx
<%@ Control Language="vb" AutoEventWireup="false" Codebehind="BestTextView.ascx.vb" Inherits="MoaWap.BestTextView" TargetSchema="http://schemas.microsoft.com/Mobile/WebUserControl" %>
<%@ Register TagPrefix="mobile" Namespace="System.Web.UI.MobileControls" Assembly="System.Web.Mobile" %>
<mobile:TextView id="tv" runat="server"></mobile:TextView>
<mobile:Panel id="Panel1" runat="server" BreakAfter="True">
    <mobile:Label id="Label1" runat="server" BreakAfter="False">[</mobile:Label>
    <mobile:Label id="lbl_currpage" runat="server" BreakAfter="False">1</mobile:Label>
    <mobile:Label id="Label2" runat="server" BreakAfter="False">/</mobile:Label>
    <mobile:Label id="lbl_count" runat="server" BreakAfter="False">0</mobile:Label>
    <mobile:Label id="Label3" runat="server" BreakAfter="False">]  </mobile:Label>
    <mobile:Label id="lbl_RoteCount" runat="server" BreakAfter="False">0</mobile:Label>
    <mobile:Label id="Label5" runat="server" BreakAfter="False">字</mobile:Label>
</mobile:Panel>
<mobile:Panel id="Panel2" runat="server" BreakAfter="True">
    <mobile:Command id="btn_first" runat="server" BreakAfter="False" Visible="False">[首页]</mobile:Command>
    <mobile:command id="btn_syy" runat="server" BreakAfter="False" Visible="False">[上页]</mobile:command>
    <mobile:command id="btn_xyy" runat="server" BreakAfter="False" Visible="False">[下页]</mobile:command>
    <mobile:Command id="btn_end" runat="server" BreakAfter="False" Visible="False">[末页]</mobile:Command>
</mobile:Panel>
<mobile:Panel id="Panel3" runat="server">
    <mobile:Label id="Label4" runat="server" BreakAfter="False">转向</mobile:Label>
    <mobile:TextBox id="txt_go" runat="server" BreakAfter="False" Size="2" Numeric="True">1</mobile:TextBox>
    <mobile:Command id="btn_go" runat="server">GO</mobile:Command>
</mobile:Panel>
<mobile:Label id="lbl_index" runat="server" Visible="False">0</mobile:Label>

用户控件源码 BestTextView.VB

委托定义#Region "委托定义"
Public Delegate Sub BestTextView_PageIndexChange()Sub BestTextView_PageIndexChange(ByVal sender As Object)
#End Region

Public MustInherit Class BestTextViewClass BestTextView
    Inherits System.Web.UI.MobileControls.MobileUserControl

Web 窗体设计器生成的代码#Region " Web 窗体设计器生成的代码 "

    '该调用是 Web 窗体设计器所必需的。
    <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()Sub InitializeComponent()

    End Sub
    Protected WithEvents tv As System.Web.UI.MobileControls.TextView
    Protected WithEvents Label3 As System.Web.UI.MobileControls.Label
    Protected WithEvents lbl_count As System.Web.UI.MobileControls.Label
    Protected WithEvents Label2 As System.Web.UI.MobileControls.Label
    Protected WithEvents lbl_currpage As System.Web.UI.MobileControls.Label
    Protected WithEvents Label1 As System.Web.UI.MobileControls.Label
    Protected WithEvents Panel1 As System.Web.UI.MobileControls.Panel
    Protected WithEvents btn_end As System.Web.UI.MobileControls.Command
    Protected WithEvents btn_xyy As System.Web.UI.MobileControls.Command
    Protected WithEvents btn_syy As System.Web.UI.MobileControls.Command
    Protected WithEvents btn_first As System.Web.UI.MobileControls.Command
    Protected WithEvents Panel2 As System.Web.UI.MobileControls.Panel
    Protected WithEvents btn_go As System.Web.UI.MobileControls.Command
    Protected WithEvents txt_go As System.Web.UI.MobileControls.TextBox
    Protected WithEvents Label4 As System.Web.UI.MobileControls.Label
    Protected WithEvents Panel3 As System.Web.UI.MobileControls.Panel
    Protected WithEvents lbl_index As System.Web.UI.MobileControls.Label
    Protected WithEvents Label5 As System.Web.UI.MobileControls.Label
    Protected WithEvents lbl_RoteCount As System.Web.UI.MobileControls.Label

    '注意: 以下占位符声明是 Web 窗体设计器所必需的。
    '不要删除或移动它。
    Private designerPlaceholderDeclaration As System.Object

    Private Sub Page_Init()Sub Page_Init(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Init
        'CODEGEN: 此方法调用是 Web 窗体设计器所必需的
        '不要使用代码编辑器修改它。
        InitializeComponent()
    End Sub

#End Region

变量/属性及事件声明#Region "变量/属性及事件声明"

    Public PageSize As Integer = 10
    Public DataString As String = ""
    Public Event BestTextViewPageIndexChange As BestTextView_PageIndexChange

    '''<summary>
    ''' 当前索引号
    '''</summary>
    Public Property SelectIndex()Property SelectIndex() As Integer
        Get
            If lbl_index.Text <> "" Then
                Return Convert.ToInt32(lbl_index.Text)
            Else
                Return -1
            End If
        End Get
        Set(ByVal Value As Integer)
            lbl_index.Text = Convert.ToString(Value)
        End Set
    End Property

    '''<summary>
    ''' 页数
    ''' </summary>
    Public ReadOnly Property PageCount()Property PageCount() As Integer
        Get
            Return Convert.ToInt32(lbl_count.Text.Trim())
        End Get
    End Property

#End Region

    Private Sub Page_Load()Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        '在此处放置初始化页的用户代码
    End Sub

    '''翻页处理
    Private Sub MyPageIdexChange()Sub MyPageIdexChange(ByVal key As String)
        Select Case key
            Case "first"
                If Convert.ToInt32(lbl_count.Text.Trim()) > 0 Then
                    lbl_currpage.Text = "1"
                End If
            Case "top"
                If Convert.ToInt32(lbl_currpage.Text.Trim()) > 1 Then
                    lbl_currpage.Text = Convert.ToString(Convert.ToInt32(lbl_currpage.Text.Trim()) - 1)
                End If
            Case "next"
                If Convert.ToInt32(lbl_currpage.Text.Trim()) < Convert.ToInt32(lbl_count.Text.Trim()) Then
                    lbl_currpage.Text = Convert.ToString(Convert.ToInt32(lbl_currpage.Text.Trim()) + 1)
                End If
            Case "last"
                If Convert.ToInt32(lbl_count.Text.Trim()) > 0 Then
                    lbl_currpage.Text = lbl_count.Text.Trim()
                End If
            Case "go"
                If txt_go.Text.Trim() <> "" Then
                    Dim igo As Integer = CInt(txt_go.Text.Trim())
                    If igo <= Convert.ToInt32(lbl_count.Text.Trim()) And igo >= 1 Then
                        lbl_currpage.Text = txt_go.Text.Trim()
                    End If
                End If
        End Select
        '触发用户控件的PageIdexChange事件
        'If Not (BestListPageIndexChange Is Nothing) Then
        RaiseEvent BestTextViewPageIndexChange(Me)
        'End If
    End Sub

    '数据绑定
    Public Overrides Sub DataBind()Sub DataBind()
        If DataString <> "" Then
            '得出当前记录总数
            Dim RoteCount As Integer = DataString.Length
            '当不同数据源绑定时恢复当前页为1(根据记录数判断是否是同一个数据源)
            Dim OldRoteCount As Integer = Convert.ToInt32(lbl_RoteCount.Text.Trim())
            If OldRoteCount <> 0 And OldRoteCount <> RoteCount Then
                lbl_currpage.Text = "1"
            End If
            lbl_RoteCount.Text = RoteCount.ToString()
            '得出页总数
            Dim tespint As Integer = RoteCount Mod PageSize
            If tespint > 0 Then
                'lbl_count.Text = Convert.ToString(CInt(RoteCount / PageSize) + 1)
                lbl_count.Text = Convert.ToString(CInt((RoteCount - tespint) / PageSize) + 1)
            Else
                lbl_count.Text = Convert.ToString(RoteCount / PageSize)
            End If
            If Convert.ToInt32(lbl_currpage.Text.Trim()) > 0 And Convert.ToInt32(lbl_currpage.Text.Trim()) <= Convert.ToInt32(lbl_count.Text.Trim()) Then
                '据当前页求出本页的开始记录和取的字数
                Dim start As Integer, tempsize As Integer = 0
                start = (Convert.ToInt32(lbl_currpage.Text.Trim()) - 1) * PageSize
                If Convert.ToInt32(lbl_currpage.Text.Trim()) = Convert.ToInt32(lbl_count.Text.Trim()) Then
                    tempsize = RoteCount Mod PageSize
                    If tempsize = 0 Then
                        tempsize = PageSize
                    End If
                Else
                    tempsize = PageSize
                End If
                tv.Text = DataString.Substring(start, tempsize)
            End If
                '---------导航按钮控制
                If Convert.ToInt32(lbl_count.Text.Trim()) <= 1 Then
                    '当只有一页时或没有记录时
                    btn_first.Visible = False
                    btn_syy.Visible = False
                    btn_xyy.Visible = False
                    btn_end.Visible = False
                    Panel1.Visible = False
                    Panel3.Visible = False
                ElseIf Convert.ToInt32(lbl_currpage.Text.Trim()) = 1 Then
                    '当为第一页时
                    btn_first.Visible = False
                    btn_syy.Visible = False
                    btn_xyy.Visible = True
                    btn_end.Visible = True
                    Panel1.Visible = True
                    Panel3.Visible = True
                ElseIf Convert.ToInt32(lbl_currpage.Text.Trim()) = Convert.ToInt32(lbl_count.Text.Trim()) Then
                    '当为最后一页时
                    btn_first.Visible = True
                    btn_syy.Visible = True
                    btn_xyy.Visible = False
                    btn_end.Visible = False
                    Panel1.Visible = True
                    Panel3.Visible = True
                ElseIf Convert.ToInt32(lbl_currpage.Text.Trim()) = 2 Then
                    '当为第二页时
                    btn_first.Visible = True
                    btn_syy.Visible = False
                    btn_xyy.Visible = True
                    btn_end.Visible = True
                    Panel1.Visible = True
                    Panel3.Visible = True
                ElseIf Convert.ToInt32(lbl_currpage.Text.Trim()) = Convert.ToInt32(lbl_count.Text.Trim()) - 1 Then
                    '当为最后一页时
                    btn_first.Visible = True
                    btn_syy.Visible = True
                    btn_xyy.Visible = False
                    btn_end.Visible = True
                    Panel1.Visible = True
                    Panel3.Visible = True
                Else
                    btn_first.Visible = True
                    btn_syy.Visible = True
                    btn_xyy.Visible = True
                    btn_end.Visible = True
                    Panel1.Visible = True
                    Panel3.Visible = True
                End If
            End If
    End Sub

    Private Sub btn_first_Click()Sub btn_first_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btn_first.Click
        MyPageIdexChange("first")
    End Sub

    Private Sub btn_syy_Click()Sub btn_syy_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btn_syy.Click
        MyPageIdexChange("top")
    End Sub

    Private Sub btn_xyy_Click()Sub btn_xyy_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btn_xyy.Click
        MyPageIdexChange("next")
    End Sub

    Private Sub btn_end_Click()Sub btn_end_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btn_end.Click
        MyPageIdexChange("last")
    End Sub

    Private Sub btn_go_Click()Sub btn_go_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btn_go.Click
        MyPageIdexChange("go")
    End Sub

End Class

使用页面 test.aspx
<%@ Register TagPrefix="mobile" Namespace="System.Web.UI.MobileControls" Assembly="System.Web.Mobile" %>
<%@ Page Language="vb" AutoEventWireup="false" Codebehind="test.aspx.vb" Inherits="MoaWap.test" %>
<%@ Register TagPrefix="uc1" TagName="BestTextView" Src="BestTextView.ascx" %>
<HEAD>
    <meta name="GENERATOR" content="Microsoft Visual Studio .NET 7.1">
    <meta name="CODE_LANGUAGE" content="Visual Basic .NET 7.1">
    <meta name="vs_targetSchema" content="http://schemas.microsoft.com/Mobile/Page">
</HEAD>
<body Xmlns:mobile="http://schemas.microsoft.com/Mobile/WebForm">
    <mobile:Form id="Form1" runat="server">
        <FONT face="宋体">
            <uc1:BestTextView id="bv" runat="server"></uc1:BestTextView>
        </FONT>
    </mobile:Form>
</body>

使用页面 test.vb

Public Class testClass test
    Inherits System.Web.UI.MobileControls.MobilePage

Web 窗体设计器生成的代码#Region " Web 窗体设计器生成的代码 "
    
    '该调用是 Web 窗体设计器所必需的。
    <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()Sub InitializeComponent()

    End Sub
    Protected WithEvents Form1 As System.Web.UI.MobileControls.Form
    
    Private Sub Page_Init()Sub Page_Init(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Init
        'CODEGEN: 此方法调用是 Web 窗体设计器所必需的
        '不要使用代码编辑器修改它。
        InitializeComponent()
    End Sub
    
#End Region

    Private WithEvents bv As BestTextView
    Private Sub Page_Load()Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        '获取用户控件
        bv = CType(Me.FindControl("bv"), BestTextView)
    End Sub

    Private Sub Form1_Activate()Sub Form1_Activate(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Form1.Activate
        filldata()
    End Sub

    Private Sub bv_dbgweIndexChange()Sub bv_dbgweIndexChange(ByVal sender As Object) Handles bv.BestTextViewPageIndexChange
        '重新绑定一下数据
        filldata()
    End Sub

    Private Sub filldata()Sub filldata()
        bv.PageSize = Config.PageTextSize
        bv.DataString = "你好,好好abcdef好好好好大厦大厦大厦大厦fffff大厦大厦大厦大厦大厦大厦大厦大aaaaaa厦大厦大厦大厦大.;'厦大厦大dsaf厦大厦大厦大厦大厦大厦大厦大厦大厦大厦大厦大厦大厦大./m厦大厦大厦大厦dsfafadfd/'gs.safdasdf大厦大厦大厦大厦大厦大厦大厦大厦大厦大厦大厦大厦大厦大厦大厦"
        bv.DataBind()
    End Sub
End Class

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