页面代码:

 <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();
}

最新文章

  1. android studio用法笔记
  2. timestamp 类型的索引
  3. Omnet++ 4.0 入门实例教程
  4. photoshop:找不到增效工具入口点
  5. django访问静态文件
  6. java md5方法 for Android
  7. ExecuteReader: CommandText 属性尚未初始化
  8. linux yum命令
  9. 20130620—ant和java杂学随笔
  10. mysql CMD命令
  11. Chapter 5 Blood Type——32
  12. url路由配置以及渲染方式
  13. windows10安装anaconda,配置tensorflow
  14. Cannot change version of project facet Dynamic Web Module to 2.4问题解决
  15. VC++ 使用attributes定义接口
  16. 【Selenium2】【Shell】
  17. IDA 逆向工程 反汇编使用
  18. pipy国内镜像的网址
  19. 今天被坑了,而且被坑的好爽! 该死的UTF-8 有 BOM 格式编码
  20. linux centos7 防火墙及端口开放相关命令

热门文章

  1. JAVA:ssm框架搭建
  2. JS获取粘贴内容
  3. 一个jboss启动shell脚本
  4. Nuget,程序员的功能包
  5. [POJ2446] Chessboard(二分图最大匹配-匈牙利算法)
  6. POJ 1985 Cow Marathon【树的直径】
  7. poj1975
  8. Lucene、Compass学习以及与SSH的整合
  9. 用svn下载github中指定目录的文件
  10. OC-category 为什么不能添加成员变量