分页及页码导航 用户控件

该控件成形如图:

主要功能如下:
用户设置每页行数 (或者不设置 则该控件默认每页10笔数据)
用户设置分页控件的数据源DataTable(或者输入查询sql)
该控件会先将传入的数据源保存到session(这样之后就不用重复查询)
然后根据用户的操作(第一页、上一页,下一页,最后页,Go页)
以及当前所在的页码
得到符合条件的返回数据 (即点击下一页或上一页后 需要正确显示的数据集)
同时 可以根据数据是否多于一页 来决定该控件是否需要显示
然后用户可以选用 这返回的DataTable数据集进行相关操作
(本控件 已加入部分js判断)
==============
示例源代码如下:
++++++++++++++++++
PageIndexCtl.ascx
+++++++++++++


+++++++++++++++++++++
PageIndexCtl.ascx.cs
+++++++++++++++++++++

++++++++++++++++++++++++
testPageIndexCtl.aspx.cs
++++++++++++++++++++++++
protected void Button1_Click(object sender, EventArgs e)
    
{
        
string strComm = " SELECT * From Table1 order by id aesc ";
        SqlResult sr 
= Broker.Execute(strComm);
        DataTable dt 
= ObjectView.GetDataView(sr).Table;

        
this.PageIndexCtl1.CountPerPage = 5;
        GridView1.DataSource 
= PageIndexCtl1.selfMeasure(dt);
        GridView1.DataBind();
    }


    
protected void Page_Init()
    
{
        
//订阅事件
        this.PageIndexCtl1.EventFirstPage += new System.EventHandler(this.EventFirstPage);
        
this.PageIndexCtl1.EventPrePage += new System.EventHandler(this.EventPrePage);
        
this.PageIndexCtl1.EventNextPage += new System.EventHandler(this.EventNextPage);
        
this.PageIndexCtl1.EventLastPage += new System.EventHandler(this.EventLastPage);
        
this.PageIndexCtl1.EventGoPage += new System.EventHandler(this.EventGoPage);
    }


    
private void EventFirstPage(object sender, EventArgs e)
    
{
        
        
this.GridView1.DataSource = this.PageIndexCtl1.dt_Result;
        
this.GridView1.DataBind();
    }

    
private void EventPrePage(object sender, EventArgs e)
    
{
        
this.GridView1.DataSource = this.PageIndexCtl1.dt_Result;
        
this.GridView1.DataBind();
    }

    
private void EventNextPage(object sender, EventArgs e)
    
{
        
this.GridView1.DataSource = this.PageIndexCtl1.dt_Result;
        
this.GridView1.DataBind();
    }

    
private void EventLastPage(object sender, EventArgs e)
    
{
        
this.GridView1.DataSource = this.PageIndexCtl1.dt_Result;
        
this.GridView1.DataBind();
    }

    
private void EventGoPage(object sender, EventArgs e)
    
{
        
this.GridView1.DataSource = this.PageIndexCtl1.dt_Result;
        
this.GridView1.DataBind();
    }


posted on 2006-12-29 19:37  freeliver54  阅读(3232)  评论(8编辑  收藏  举报

导航