欢迎光临
我们一直在努力

建站超值云服务器,限时71元/月

listcontrol.aspx
<%@ control language="vb" autoeventwireup="false" codebehind="listcontrol.ascx.vb" inherits="govoa.listcontrol" targetschema="http://schemas.microsoft.com/intellisense/ie5" %>
共有<asp:label id="lblrecordcount" forecolor="red" runat="server" />条记录  当前为<asp:label id="lblcurrentpage" forecolor="red" runat="server" />/<asp:label id="lblpagecount" forecolor="red" runat="server" />页
<asp:linkbutton id="lblprevious" runat="server" text="上一页"></asp:linkbutton>
<asp:linkbutton id="lblnext" runat="server" text="下一页"></asp:linkbutton> 
<asp:dropdownlist id="numperpage" runat="server" autopostback="true">
    <asp:listitem value="5">
        5行/页</asp:listitem>
    <asp:listitem value="8" selected="true">
        8行/页</asp:listitem>
    <asp:listitem value="10">
        10行/页</asp:listitem>
    <asp:listitem value="15">
        15行/页</asp:listitem>
    <asp:listitem value="20">
        20行/页</asp:listitem>
    <asp:listitem value="25">
        25行/页</asp:listitem>
    <asp:listitem value="30">
        30行/页</asp:listitem>
    <asp:listitem value="35">
        35行/页</asp:listitem>
    <asp:listitem value="40">
        40行/页</asp:listitem>
</asp:dropdownlist>
<asp:textbox id="txtpage" runat="server" width="30"></asp:textbox><asp:button id="btngo" runat="server" text="转到"></asp:button>

listcontrol.aspx.vb

imports system.data.sqlclient
public mustinherit class listcontrol
    inherits system.web.ui.usercontrol
    protected withevents lblrecordcount as system.web.ui.webcontrols.label
    protected withevents lblcurrentpage as system.web.ui.webcontrols.label
    protected withevents lblpagecount as system.web.ui.webcontrols.label
    protected withevents lblprevious as system.web.ui.webcontrols.linkbutton
    protected withevents lblnext as system.web.ui.webcontrols.linkbutton
    protected withevents numperpage as system.web.ui.webcontrols.dropdownlist
    protected withevents txtpage as system.web.ui.webcontrols.textbox
    protected withevents btngo as system.web.ui.webcontrols.button
    private m_datacontainer as repeater
    private m_datasource as string
    private m_torefresh as boolean = false

    private myconn as sqlconnection
    private recordcount, pagecount, currentpage as integer

    / <summary>
    / 取得需要绑定的控件
    / </summary>

    public property getrelatedcontrol() as repeater
        get
            return m_datacontainer
        end get
        set(byval value as repeater)
            m_datacontainer = value
        end set
    end property

    public property torefresh() as boolean
        get
            return m_torefresh
        end get
        set(byval value as boolean)
            m_torefresh = value
        end set
    end property

    public property getrelatedsqlstr() as string
        get
            return m_datasource
        end get
        set(byval value as string)
            m_datasource = value
            if m_torefresh then
                refreshdata()
            end if
        end set
    end property

#region " web 窗体设计器生成的代码 "

    该调用是 web 窗体设计器所必需的。
    <system.diagnostics.debuggerstepthrough()> private sub initializecomponent()

    end sub

    private sub page_init(byval sender as system.object, byval e as system.eventargs) handles mybase.init
        codegen: 此方法调用是 web 窗体设计器所必需的
        不要使用代码编辑器修改它。
        initializecomponent()
    end sub

#end region

    private sub page_load(byval sender as system.object, byval e as system.eventargs) handles mybase.load
        在此处放置初始化页的用户代码
        myconn = new sqlconnection(system.configuration.configurationsettings.appsettings("connectionstring"))
        myconn.open()
        viewstate("pagesize") = numperpage.selecteditem.value.tostring()
        if not page.ispostback then
            bindcontrol()
            currentpage = 0
            viewstate("pageindex") = 0

            计算总共有多少记录
            recordcount = calculaterecord()
            lblrecordcount.text = recordcount.tostring()

            计算总共有多少页
            pagecount = fix((recordcount + int32.parse(numperpage.selecteditem.value)) / convert.toint32(viewstate("pagesize").tostring())) – (iif(recordcount mod convert.toint32(viewstate("pagesize").tostring()) <> 0, 0, 1))  todo: unsupported feature: conditional (?) operator.
            lblpagecount.text = pagecount.tostring()
            if pagecount <= 1 then
                lblnext.enabled = false
            end if
            viewstate("pagecount") = pagecount
        end if
    end sub

    private sub refreshdata()
        myconn = new sqlconnection(system.configuration.configurationsettings.appsettings("connectionstring"))
        myconn.open()
        viewstate("pagesize") = numperpage.selecteditem.value.tostring()

        bindcontrol()
        currentpage = 0
        viewstate("pageindex") = 0

        计算总共有多少记录
        recordcount = calculaterecord()
        lblrecordcount.text = recordcount.tostring()

        计算总共有多少页

        pagecount = fix((recordcount + int32.parse(numperpage.selecteditem.value)) / convert.toint32(viewstate("pagesize").tostring())) – (iif(recordcount mod convert.toint32(viewstate("pagesize").tostring()) <> 0, 0, 1)) todo: unsupported feature: conditional (?) operator.
        lblpagecount.text = pagecount.tostring()
        if pagecount <= 1 then
            lblnext.enabled = false
        end if
        viewstate("pagecount") = pagecount

    end sub
    / <summary>
    / 绑定控件
    / </summary>
    private sub bindcontrol()

        m_datacontainer.datasource = createsource()
        m_datacontainer.databind()
        
        lblnext.enabled = true
        lblprevious.enabled = true
        if currentpage = pagecount – 1 then
            lblnext.enabled = false
        end if
        if currentpage = 0 then
            lblprevious.enabled = false
        end if
        lblcurrentpage.text = (currentpage + 1).tostring()
        txtpage.text = (currentpage + 1).tostring()
    end sub bindcontrol

    / <summary>
    / 产生datalist的dataview
    / </summary>
    / <returns></returns>
    private function createsource() as dataview

        dim startindex as integer

        设定导入的起终地址
        startindex = currentpage * convert.toint32(viewstate("pagesize").tostring()) 计算起始索引
        dim ds as new dataset()

        dim myadapter as new sqldataadapter(m_datasource, myconn)
        myadapter.fill(ds, startindex, convert.toint32(viewstate("pagesize").tostring()), "score")

        return ds.tables("score").defaultview
    end function createsource

    / <summary>
    / 计算有多少记录
    / </summary>
    / <returns></returns>
    public function calculaterecord() as integer

        dim ds as new dataset()

        dim myadapter as new sqldataadapter(m_datasource, myconn)
        myadapter.fill(ds, "temptable")

        return ds.tables("temptable").defaultview.count
    end function calculaterecord

    private sub btngo_click(byval sender as system.object, byval e as system.eventargs) handles btngo.click
        try
            dim inputvalue as integer = convert.toint32(txtpage.text)
            pagecount = cint(viewstate("pagecount"))
            if inputvalue <= pagecount and inputvalue > 0 then
                currentpage = convert.toint32(txtpage.text) – 1
            else
                currentpage = cint(viewstate("pageindex"))
            end if
            viewstate("pageindex") = currentpage
        catch
        end try
        bindcontrol()
    end sub

    private sub numperpage_selectedindexchanged(byval sender as system.object, byval e as system.eventargs) handles numperpage.selectedindexchanged
        try
            viewstate("pagesize") = numperpage.selecteditem.value

            currentpage = 0
            viewstate("pageindex") = 0

            计算总共有多少记录
            recordcount = calculaterecord()
            lblrecordcount.text = recordcount.tostring()

            计算总共有多少页
            pagecount = recordcount / convert.toint32(viewstate("pagesize").tostring()) + (iif(recordcount mod convert.toint32(viewstate("pagesize").tostring()) = 0, 0, 1)) todo: unsupported feature: conditional (?) operator.
            lblpagecount.text = pagecount.tostring()
            viewstate("pagecount") = pagecount

            bindcontrol()
        catch
        end try
    end sub

    private sub lblprevious_click(byval sender as system.object, byval e as system.eventargs) handles lblprevious.click
        currentpage = cint(viewstate("pageindex"))
        pagecount = cint(viewstate("pagecount"))

        if currentpage > 0 then
            currentpage -= 1
        end if

        viewstate("pageindex") = currentpage

        bindcontrol()
    end sub

    private sub lblnext_click(byval sender as system.object, byval e as system.eventargs) handles lblnext.click
        currentpage = cint(viewstate("pageindex"))
        pagecount = cint(viewstate("pagecount"))

        if currentpage < pagecount – 1 then
            currentpage += 1
        end if

        viewstate("pageindex") = currentpage

        bindcontrol()
    end sub
end class

调用
自己看着办
几点说明:
这个是测试版本

掉用如下
        listcontrol1.getrelatedcontrol = rptcontent
        listcontrol1.torefresh = true  
        listcontrol1.getrelatedsqlstr = new bizlogic.dbfilm().selectfilmstr(ddl_type.selecteditem.value, tbx_keyword.text)

如果有bug
请和 h.xue@163.net联系,多谢
一点说明:
我这里分页是repeater ,但是如果要用datalist也很容易,这个我就不说明了。大家一看就知道

赞(0)
版权申明:本站文章部分自网络,如有侵权,请联系:west999com@outlook.com 特别注意:本站所有转载文章言论不代表本站观点! 本站所提供的图片等素材,版权归原作者所有,如需使用,请与原作者联系。未经允许不得转载:IDC资讯中心 »
分享到: 更多 (0)

相关推荐

  • 暂无文章