页面代码:

 <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. (十九)python 3 内嵌函数和闭包

    内嵌函数:函数里又嵌套一个函数 def fun1(): print('fun1()在被调用') def fun2(): print('fun2()在被调用') fun2() 闭包: 闭包是函数里面嵌套 ...

  2. JS 获取字符串中的url并返回其下标索引

    //获取字符串中的url极其下标索引 function getHttpUrlArray(s) { var s1 = s.match(/http.*/); if(s1 == null) { return ...

  3. 关于hibernate中的 lazy="false“

    如上图所示,warehousePicked 中包含了warehousePicking 同时,数据库中warehousePicking存在数据 ,但是在debug 时warehousePicked的be ...

  4. iptables工具

    http://www.linuxidc.com/Linux/2012-12/77074.htm iptables 指令 语法: iptables [-t table] command [match]  ...

  5. unittest多线程生成报告(BeautifulReport)

    前言 selenium多线程跑用例,这个前面一篇已经解决了,如何生成一个测试报告这个是难点,刚好在github上有个大神分享了BeautifulReport,完美的结合起来,就能生成报告了. 环境必备 ...

  6. java常见问题集锦

    Eclipse 编译错误 Access restriction:The type *** is not accessible due to restriction on... 解决方案 Eclipse ...

  7. Laya 利用JS进行反射

    Laya 利用JS进行反射 @author ixenos 当需要配表调用函数时,可以利用js的eval来调用 1.在配置js中写下: function callAsFunc(funcName){ ev ...

  8. hdu 1232水

    #include<stdio.h> #define N 1000 int pre[N]; int find(int n ){ return pre[n]=n==pre[n]?n:find( ...

  9. SA模板

    #include<cstdio> #include<algorithm> #include<cstring> using namespace std; ; char ...

  10. iOS 调用系统相册 相机 时,显示中文标题

    解决手机语言已经设置显示中文 在调用系统相册.相机界面 时显示英文问题, 在 info.plist里面添加Localized resources can be mixed YES 表示是否允许应用程序 ...