May 28 2008

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="lesson121.aspx.cs" Inherits="lesson121" %>
<%@ Import Namespace="System.Data.SqlClient" %>
<%@ Import Namespace="System.Data" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
    <title>无标题页</title>
    <script runat="server" language="c#">
        int currentpage = 0;
        int maxpage=0;

        public SqlConnection getCon()
        {
            SqlConnection con = new SqlConnection("Data Source=.;User ID=sa;Password=;Initial catalog=pubs;");
            con.Open();
           
            return con;
        }
    public int getMaxRow()
    {
        String sql = "select count(*) from author";
  
        SqlConnection con = this.getCon();

        SqlCommand cmd = con.CreateCommand();

        cmd.CommandType = CommandType.Text;

        cmd.CommandText = sql;

        SqlDataReader sdr = cmd.ExecuteReader();

        int result = 0;
       
        while (sdr.Read())
        {
            result = Convert.ToInt32(sdr[0].ToString());
        }
        cmd.Dispose();

        con.Close();

        return result;
       
    }

        public int getMaxPage()
        {
            int maxrow = this.getMaxRow();
       
            if (maxrow < 1)
            {
                return 0;
            }
            if (maxrow % 5 == 0)
            {
                return maxrow / 5;
            }
            else
            {
                return maxrow / 5 + 1;
            }
        }
    
        public DataTable getPageData(int cp)
        {
            int maxpage = this.getMaxPage();
           
            if (cp < 1)
            {
                cp = 1;
            }
          
            int pagenum = (cp - 1) * 5;
           
            String sql = "select top 5 * from author where au_id not in (select top " + pagenum + " au_id from author order by au_id desc) order by au_id desc";
           
            SqlConnection con = this.getCon();

            SqlDataAdapter sda = new SqlDataAdapter(sql, con);

            DataTable datatable = new DataTable("author");

            sda.Fill(datatable);

            sda.Dispose();

            con.Close();

            return datatable;
           
        }
       
       
    </script>
</head>
<body>
    <form id="form1" runat="server">
    <p><input type="text" id="selectnum" /> <input type="submit" value="Click" /></p>
    <table align="center" style="font-size:12px;" bgcolor="yellow">
    <tr >
    <td>作者编号</td>
    <td>作者姓</td>
    <td>作者名</td>
    <td>作者电话</td>
    </tr>
    <%
       
       if (Request.QueryString["cp"] != null)  
        {
           currentpage = Convert.ToInt32(Request.QueryString["cp"].ToString());
       }
       if (currentpage < 0)
       {
           currentpage = 1;
       }
      
       Response.Write("+++" + currentpage);
          DataTable author_table = getPageData(currentpage);
     int rowcount = author_table.Rows.Count;
        Response.Write("+++"+rowcount);
        for (int i = 0; i < rowcount; i++)
        {
            %>
           
            <tr>
            <td><%=author_table.Rows[i]["au_id"].ToString() %></td>
            <td><%=author_table.Rows[i]["au_fname"].ToString() %></td>
            <td><%=author_table.Rows[i]["au_lname"].ToString() %></td>
            <td><%=author_table.Rows[i]["phone"].ToString()%></td>
            </tr>
           
            <%
        }
                maxpage = this.getMaxPage();
                //Session["cp"] = currentpage;
     %>
   
   
   
    </table>
   
    <p align="center" style="font-size:12px;">
    <a href="lesson121.aspx?cp=<%=1 %>">第一页</a>
    <%if(currentpage>1) {%><a href="lesson121.aspx?cp=<%=currentpage-1 %>">上一页</a><%} %> &nbsp;
    <%if(currentpage<maxpage){ %><a href="lesson121.aspx?cp=<%=currentpage+1 %>">下一页</a><%} %>
    <a href="lesson121.aspx?cp=<%=maxpage %>">最末页</a>
    </p>
    </form>
</body>
</html>

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值