页面代码:

 <div style="margin-top:0px;">共<asp:Label ID="lb_count" runat="server" Text ="Label"></asp:Label>条记录
共<asp:Label ID="lb_page" runat="server" Text="Label"></asp:Label>页&nbsp;
当前第<asp:Label ID="lb_CurrentPage" runat="server" Text=""></asp:Label>页
<br />
<asp:LinkButton ID="LinkFirst" runat="server" OnClick="LinkFirst_Click"> 第一页
</asp:LinkButton>
<asp:LinkButton ID="LinkUp" runat="server" OnClick="LinkUp_Click"> 上一页
</asp:LinkButton>
<asp:LinkButton ID="LinkDown" runat="server" OnClick="LinkDown_Click"> 下一页
</asp:LinkButton>
<asp:LinkButton ID="LinkLast" runat="server" OnClick="LinkLast_Click"> 最后一页
</asp:LinkButton>转到第<asp:DropDownList ID="DropDownList1" runat="server" OnSelectedIndexChanged="DropDownList1_SelectedIndexChanged" AutoPostBack="True">
</asp:DropDownList>页</div>

后台代码:

protected SqlDataAdapter da;
protected DataSet ds;
private void getArticle() //取得Article 数据
{
string connectionString = "Server=.;database=Flower;uid=sa;pwd=zhuwenfan";
SqlConnection myconn = new SqlConnection(connectionString);//取连接字符串,建立连接
da = new SqlDataAdapter();
da.SelectCommand = new SqlCommand("select * from FLOWERS_ORDER order by O_ID desc", myconn);
ds = new DataSet(); try
{
myconn.Open();
da.Fill(ds, "Article");
myconn.Close();
}
catch (SqlException e1)
{
Response.Write(e1.ToString());
}
int cup = Convert.ToInt32(this.lb_CurrentPage.Text); //当前页数,初始化为地1 页
PagedDataSource ps = new PagedDataSource();
ps.DataSource = ds.Tables["Article"].DefaultView;
ps.AllowPaging = true;
ps.PageSize = ; //每页显示的数据的行数
ps.CurrentPageIndex = cup - ;
lb_count.Text = ps.DataSourceCount.ToString(); //获取记录总数
lb_page.Text = ps.PageCount.ToString(); //获取总页数
if (!IsPostBack)
{
for (int i = ; i < ps.PageCount + ; i++)
{
this.DropDownList1.Items.Add(i.ToString());
}
LinkUp.Enabled = true;
LinkDown.Enabled = true;
}
try
{
DropDownList1.SelectedItem.Text = cup.ToString();
ListView1.DataSource = ps;
ListView1.DataBind();
}
catch (Exception ex)
{
Response.Write(ex.Message);
}
}
protected void LinkDown_Click(object sender, EventArgs e) //下一页按钮代码
{
try
{
lb_CurrentPage.Text = Convert.ToString(Convert.ToInt32(lb_CurrentPage.Text) + );
DropDownList1.SelectedValue = lb_CurrentPage.Text;
getArticle();
}
catch
{
Response.Write("<script language=javascript>" + "alert(\"已经是最后一页\")" + "</script>");
lb_CurrentPage.Text = "";
getArticle(); }
}
protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e) //跳转到指定页代码
{
int page = Convert.ToInt16((DropDownList1.SelectedItem.Value));
lb_CurrentPage.Text = page.ToString();
getArticle();
}
protected void LinkUp_Click(object sender, EventArgs e) //上一页按钮代码
{
try
{
if (Convert.ToInt16(lb_CurrentPage.Text) > )
{
lb_CurrentPage.Text =
Convert.ToString(Convert.ToInt32(lb_CurrentPage.Text) - );
DropDownList1.SelectedValue = lb_CurrentPage.Text;
getArticle();
}
else
{
Response.Write("<script>alert('已经是第一页');location.replace(location.href);</script>");
}
}
catch
{
Response.Write("<script>alert('已经是第一页');location.replace(location.href);</script>");
}
}
protected void LinkFirst_Click(object sender, EventArgs e) //跳到第一页代码
{
if (lb_CurrentPage.Text != "")
{
lb_CurrentPage.Text = "";
}
else
{
Response.Write("<script language=javascript>" + "alert(\" 已经是第一页\")" + "</script>");
}
getArticle();
}
protected void LinkLast_Click(object sender, EventArgs e) //跳到最后一页代码
{
if (lb_CurrentPage.Text.ToString() != lb_page.Text.ToString())
{
lb_CurrentPage.Text = lb_page.Text.ToString();
}
else
{
Response.Write("<script language=javascript>" + "alert(\"已经是最后一页\")" + "</script>");
}
getArticle();
}

asp.net listview 实现分页浏览效果的更多相关文章

  1. Android中使用ListView实现分页刷新(线程休眠模拟)

    当要显示的数据过多时,为了更好的提升用户感知,在很多APP中都会使用分页刷新显示,比如浏览新闻,向下滑动到当前ListView的最后一条信息(item)时,会提示刷新加载,然后加载更新后的内容.此过程 ...

  2. Android中使用ListView实现分页刷新(线程休眠模拟)(滑动加载列表)

    当要显示的数据过多时,为了更好的提升用户感知,在很多APP中都会使用分页刷新显示,比如浏览新闻,向下滑动到当前ListView的最后一条信息(item)时,会提示刷新加载,然后加载更新后的内容.此过程 ...

  3. ASP利用Recordset实现分页

    <!--#INCLUDE FILE="../function/db.asp" --> <!--#INCLUDE FILE="../function/co ...

  4. Android基本控件之listView(三)<用ListView实现分页加载>

    我们之前讨论了ListView的基本使用方法和ListView的优化 今天我们再来讨论一个关于ListView的一个新的东西~就是分页加载.那么什么是分页加载呢?简单点说,就是"下拉刷新&q ...

  5. android UI进阶之实现listview的分页加载

    上篇博文和大家分享了下拉刷新,这是一个用户体验非常好的操作方式.新浪微薄就是使用这种方式的典型. 还有个问题,当用户从网络上读取微薄的时候,如果一 下子全部加载用户未读的微薄这将耗费比较长的时间,造成 ...

  6. 学习ASP.NET MVC(十一)——分页

    在这一篇文章中,我们将学习如何在MVC页面中实现分页的方法.分页功能是一个非常实用,常用的功能,当数据量过多的时候,必然要使用分页.在今天这篇文章中,我们学习如果在MVC页面中使用PagedList. ...

  7. ListView实现分页加载(一)制作Demo

    一.什么是分页加载 在下面的文章中,我们来讲解LitView分页加载的实现.什么是分页加载呢?我们先看几张效果图吧,如下:                                       ...

  8. iOS- UIScrollView、UIPageControl分页浏览图片

    1.先介绍下UIScrollView的常见属性 @property(nonatomic) CGPoint contentOffset; // 记录UIScrollView滚动的位置 @property ...

  9. Asp 解析 XML并分页显示

    Asp 解析 XML并分页显示 Asp 解析 XML并分页显示,演示样例源代码例如以下: <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Tr ...

随机推荐

  1. pwntools使用简介3

    连接 本地process().远程remote().对于remote函数可以接url并且指定端口. IO模块 下面给出了PwnTools中的主要IO函数.这个比较容易跟zio搞混,记住zio是read ...

  2. 03003_Http响应

    1.Http协议 (1)状态码: (2)常用的状态码如下: 200 :请求成功: 302 :请求重定向: 304 :请求资源没有改变,访问本地缓存: 404 :请求资源不存在.通常是用户路径编写错误, ...

  3. 理解js的几个关键问题(2): 对象、 prototype、this等

    参考文档:http://www.cnblogs.com/ranran/archive/2014/05/19/3737217.html http://speakingjs.com/es5/ch17.ht ...

  4. 命令行可以执行python脚本,jenkins里执行报错:cannot find Chrome binary

    “selenium.common.exceptions.WebDriverException: Message: unknown error: cannot find Chrome binary”这个 ...

  5. POJ3037 Skiing

    Skiing 题目大意: 给定一个M*N的网格,已知在每个网格中的点可以向上下左右四个方向移动一个单位,每个点都有一个高度值. 从每个点开始移动时存在一个速度值,从A点移动到B点,则此时B点的速度为& ...

  6. HDU3785寻找大富翁~~真真切切的水题

    寻找大富翁 Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Subm ...

  7. Request获取Session的两种方式

    1.无请求参数 public HttpSession getSession() 获取当前request关联的session,如果当前request没有session,创建一个session. 2.有请 ...

  8. bitcms-比特内容管理系统 3.1版源码发布

    bitcms比特内容管理系统,经过几个版本的更新和客户的使用已经基本上完善了.下面主要介绍下他的运行环境和功能. 一.运行环境:windows server+IIS bitcms采用Entity Fr ...

  9. 逆序对数列(BZOJ 2431)

    题目描述 对于一个数列{ai},如果有i<j且ai>aj,那么我们称ai与aj为一对逆序对数.若对于任意一个由1~n自然数组成的数列,可以很容易求出有多少个逆序对数.那么逆序对数为k的这样 ...

  10. Flex的Combobox组件使用技巧

    1.显示提示设置Prompt属性可以为Combobox添加一个默认提示.如果没有设置selectedIndex,默认selectedIndex=-1,就显示Prompt的内容.Flex3如果不设置Pr ...