ASPNETPager常用属性

<webdiyer:aspnetpager id="AspNetPager1" runat="server"
       alwaysshow="True"
       PageSize="5"
       custominfosectionwidth="20%"
       custominfotextalign="Right"
       firstpagetext="第一页"
       horizontalalign="Left"
       lastpagetext="末一页"
       navigationbuttontype="Image"
       nextpagetext="后一页"
       pageindexboxtype="TextBox"
       pagingbuttonspacing="8px"
       prevpagetext="前一页"
       showcustominfosection="Right"
       showpageindexbox="Always"
       textafterpageindexbox="页"
       UrlPaging="true"
       textbeforepageindexbox="跳到第"
       width="97%"
       onpagechanged="AspNetPager1_PageChanged">
</webdiyer:aspnetpager>
alwaysshow:总是显示分页控件;
PageSize:指定每页显示的记录数;
custominfosectionwidth:用户自定义信息区的宽度;
custominfotextalign:用户自定义信息区的对齐方式;
firstpagetext:第一页按钮上显示的文本;
horizontalalign:内容水平对齐方式;
lastpagetext:最后页按钮上显示的文本;
navigationbuttontype:第一页、下一页、最后一页按钮的类型;
nextpagetext:下一页按钮上显示的文本;
pageindexboxtype:指示页索引框的显示类型:有TextBOX和dropdownlist两种;
pagingbuttonspacing:导航页按钮的间距;
prevpagetext:上一页按钮的显示的文本;
showcustominfosection:显示当前页和总页信息,默认为不显示,值为LEFT时将显示在页索引前,为right时显示在页索引后;
showpageindexbox:指定页索引文本框或下拉框的显示方式;
textafterpageindexbox:指定页索引文本框或下拉框后的文本;
UrlPaging:是够使用URL传递分页的方式来分页;
textbeforepageindexbox:指定页索引文本框或下拉框前面显示的文本;
width:该控件的宽度;
CustomInfoHTML:指定要显示在用户自定义信息区的用户自定义HTML信息文本

using System;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.Data.SqlClient;
public partial class _Default : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        Bind();
    }
    private void Bind()
    {
        int pageindex = 1;
        int pagenum = AspNetPager1.PageSize;
        if (Request["page"] != null)
        {
            pageindex =Convert.ToInt32(Request["page"]);
        }
        DataSet ds = new DataSet();
        SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["constr"].ToString ());
        SqlConnection con1 = new SqlConnection(ConfigurationManager.ConnectionStrings["constr"].ToString());
        SqlDataAdapter sda = new SqlDataAdapter("select top (@pagenum) * from pagetest where id not in (select top  (@pagenum*(@pageindex-1)) id from pagetest)", con);
        sda.SelectCommand.Parameters.AddWithValue("pagenum",pagenum);
        sda.SelectCommand.Parameters.AddWithValue("pageindex",pageindex);
        sda.Fill(ds);
        SqlCommand cmd = new SqlCommand("select count(*) from pagetest", con1);
        con1.Open();
        AspNetPager1.RecordCount =Convert.ToInt32(cmd.ExecuteScalar());
        con.Close();
        AspNetPager1.CustomInfoHTML = "共" + AspNetPager1.RecordCount + "条记录      " + AspNetPager1.CurrentPageIndex + "/" + AspNetPager1.PageCount;
        GridView1.DataSource = ds.Tables[0].DefaultView;
        GridView1.DataBind();
    }
    protected void AspNetPager1_PageChanged(object sender, EventArgs e)
    {
        Bind();
    }
}
深入分析CurrentPageIndex、RecordCount、 PageCount、 PageSize:

pagecount:

public int PageCount
{
    get
    {
        if (this.RecordCount == 0)
        {
            return 1;
        }
        return (int) Math.Ceiling((double) (((double) this.RecordCount) / ((double) this.PageSize)));
    }
}
recordcount:

public int RecordCount
{
    get
    {
        if (this.cloneFrom != null)
        {
            return this.cloneFrom.RecordCount;
        }
        object obj2 = this.ViewState["Recordcount"];
        if (obj2 != null)
        {
            return (int) obj2;
        }
        return 0;
    }
    set
    {
        this.ViewState["Recordcount"] = value;
    }
}
CurrentPageIndex:

public int CurrentPageIndex
{
    get
    {
        if (this.cloneFrom != null)
        {
            return this.cloneFrom.CurrentPageIndex;
        }
        object obj2 = this.ViewState["CurrentPageIndex"];
        int num = (obj2 == null) ? 1 : ((int) obj2);
        if ((num > this.PageCount) && (this.PageCount > 0))
        {
            return this.PageCount;
        }
        if (num < 1)
        {
            return 1;
        }
        return num;
    }
    set
    {
        int pageCount = value;
        if (pageCount < 1)
        {
            pageCount = 1;
        }
        else if (pageCount > this.PageCount)
        {
            pageCount = this.PageCount;
        }
        this.ViewState["CurrentPageIndex"] = pageCount;
    }
}
PageSize:

public int PageSize
{
    get
    {
        int num;
        if ((!string.IsNullOrEmpty(this.UrlPageSizeName) && !base.DesignMode) && (int.TryParse(this.Page.Request.QueryString[this.UrlPageSizeName], out num) && (num > 0)))
        {
            return num;
        }
        if (this.cloneFrom != null)
        {
            return this.cloneFrom.PageSize;
        }
        object obj2 = this.ViewState["PageSize"];
        if (obj2 != null)
        {
            return (int) obj2;
        }
        return 10;
    }
    set
    {
        this.ViewState["PageSize"] = value;
    }
}

  

时间: 2024-08-26 06:27:15

ASPNETPager常用属性的相关文章

ASPNETPager常用属性(近来用到分页属性)

ASPNETPager常用属性 建议去封装好,然后调用这样比较容易 <webdiyer:aspnetpager id="AspNetPager1" runat="server" alwaysshow="True" PageSize="5" custominfosectionwidth="20%" custominfotextalign="Right" firstpagetext=&

window对象的常用属性,常用方法

window对象的常用属性: window.self 返回当前窗口的引用 window.parent   返回当前窗体的父窗体对象 window.top 返回当前窗体最顶层的父窗体的引用 window.outerwidth       返回当前窗口的外部宽 window.outerheight  返回当前窗口的外部高 window.innerwidth       返回当前窗口的可显示区域宽 window.innerheight  返回当前窗口的可显示区域高 提示:通过直接在Chrome控制台中

样式常用属性

笔记信息 复习: 表单作用: 从使用的角度上说:html提供了一个输入内容的途径. 从服务器的角度:提供了一个收集信息的途径. 以便客户端和服务器进行交互. 例:注册页面,上传文件. 3种常见元素:input select textarea Input的十种常见类型: text,password,radio,checkbox,submit,reset,button,image,hidden,file Radio中name应该保持相同,以确保在单选按钮中的元素完成互斥. Checkbox中name

UIScrollView 的常用属性和方法

1.继承关系:UIView -> UIResponder -> NSObject2.代理:UIScrollViewDelegate// *2.1 一但偏移量发生变化就会调用  - (void)scrollViewDidScroll:(UIScrollView *)scrollView;// *2.2 将要缩放时就return谁   2.2.1 由于要缩放内容,我们需要设置最大和最小的缩放比例    scrollView.minimumZoomScale = 1.0f;    scrollVie

CoreAnimation 核心动画 的一些常用属性 和 方法

1.常用属性: frame   bounds   center   alpha    Transition 过渡    transform 动画效果 2.常用方法: +(void)setAnimationDelegate:(id)delegate; +(void)setAnimationWillStartSelector:(SEL)selector; 当动画结束的时候,执行delegate对象的selector,并且把beginAnimations:context:中传入的参数传进selecto

SVG DOM常用属性和方法介绍

将以Adobe SVG Viewer提供的属性和方法为准,因为不同解析器对JavaScript以及相关的属性和方法支持的程度不同,有些方法和属性是某个解析器所特有的.SVG支持DOM2标准. 12.2.1  文档初始化相关 evt属性 evt表示事件本身,可以通过evt获取与当前事件相关的信息,用户可以在script中定义响应函数,进行相应的处理.它与普通JavaScript脚本中的event基本相同,只不过在普通JavaScript的脚本中简写成“e”. ownerDocument属性 通过引

UITableView的常用属性和cell的内存优化

UITableView的常用属性: 分割线颜色设置: 1> 设置separatorStyle: 分割线的颜色 方法:tableView.separatorStyle = UITableViewCellSeparatorStyleSingleLine; 2> 设置separatorColor 不用系统枚举的值,自己设定颜色的值 24bitRGB R:8bit G:8bit B:8bit =========== 32bitRGBA R:8bit G:8bit B:8bit A:8bit 表示透明度

Android 控件布局常用属性

<!--单个控件经常用到android:id -- 为控件指定相应的IDandroid:text -- 指定控件当中显示的文字,需要注意的是,这里尽量使用strings.xml文件当中的字符串android:grivity -- 指定控件的基本位置,比如说居中,居右等位置android:textSize -- 指定控件当中字体的大小android:background -- 指定该控件所使用的背景色,RGB命名法 android:width -- 指定控件的宽度android:height --

013.泛型、窗体常用属性

泛型: *是C#语言2.0和通用语言运行时的新特性*利用参数化类型将类型抽象化,从而实现更为灵活的服用 优点:*缓解了代码膨胀的情况*提供了一个强类型的编程模型,类型安全*值类型不再需要装箱操作*性能的到提高*代码可读性好 1.泛型方法 既可以放在普通类中也可以定义在泛型类中 访问修饰符[可选修饰符]返回类型 方法名<参数化类型>(参数列表){} 方法名(参数)://推断类型 根据给的类型推断出来他的参数化类型用的应该是什么方法名<类型>(参数): 类型参数:习惯上用T或者T开头的