程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
 程式師世界 >> 編程語言 >> .NET網頁編程 >> .NET實例教程 >> 自己認為比較好的分頁

自己認為比較好的分頁

編輯:.NET實例教程
前台代碼 Html

<script type="text/Javascript">
function pager(fullUrl,currentPage,maxPage)
    ...{
        document.write("<font style=''font-family:宋體;font-size:9pt;''>");
        if (currentPage==1)...{
            document.write("<font color=''#aaaaaa''><font style=''font-family:webdings''>9</font> ");
            document.write("<font style=''font-family:webdings''>7</font></font> <b>");
        }else...{
            document.write("<a href=''?" + fullUrl + "currentpage=1''><font style=''font-family:webdings''>9</font></a> ");
            document.write("<a href=''?" + fullUrl + "currentpage=" + (currentPage-1) + "''><font style=''font-family:webdings''>7</font></a> <b>");
        }
        var i;
        var j;
        var k;
 &nbsp;      if (currentPage-5<1)...{
            j=1;
        }else...{
            j=currentPage-5;
        }
        if (currentPage+5<maxPage)...{
            k=currentPage+5;
        }else...{
            k=maxPage;
        }
        for(i=j;i<k+1;i++)...{
            if (currentPage==i)...{
                document.write("<font color=''red''>" + i + "</font> ");
      }else...{
                document.write("<a href=''?" + fullUrl + "currentpage=" + i +"''>" + i + "</a> ");
            }
        }
        if (currentPage==maxPage)...{
            document.write("</b><font color=''#aaaaaa''><font style=''font-family:webdings''>8</font> ");
            document.write("<font style=''font-family:webdings''>:</font></font>")    ;
        }else ...{
            document.write("</b><a href=''?" + fullUrl + "currentpage=" + (currentPage +1) + "''><font style=''font-family:webdings''>8</font></a> ");
            document.write("<a href=''?" + fullUrl + "currentpage=" + maxPage + "''><font style=''font-family:webdings''>:</font></a>");
        }
        document.write("</font>");
    }    
</script>

 

後台綁定代碼



 protected void bindDatalist()
...{

        int currentPage = 1;
        if (Request.QueryString["currentpage"] != null)
        ...{
            try
            ...{
                currentPage = Convert.ToInt32(Request.QueryString["currentpage"]);
            }
            catch
            ...{
                currentPage = 1;
            }
        }

        int rowsPerPage = 10;

        string sql = "select count(*) from per_info where per_check=1";

        int rowsTotal = (int)LiTianPing.DBUtility.DbHelperSQL.GetSingle(sql);

 int maxPage = 1;
        if (rowsTotal % rowsPerPage == 0)
        ...{
            maxPage = (int)rowsTotal / rowsPerPage;
        }
        else
        ...{
            maxPage = (int)rowsTotal / rowsPerPage + 1;
        }
        if (maxPage == 0)
        ...{
            maxPage = 1;
        }

        if (currentPage < 1)
        ...{
            currentPage = 1;
        }
        else if (currentPage > maxPage)
        ...{
            currentPage = maxPage;
        }

        pager.Text = "<script language=''Javascript''>pager(''''," + currentPage.ToString() + "," + maxPage.ToString() + ");</script>";

        if (rowsTotal != 0)
        ...{
            if (currentPage == 1)
            ...{
                sql = "select  top " + rowsPerPage.ToString() + " id,per_photoname,per_name,per_age,per_work,per_type,per_something,per_danwei,per_nuber from per_info where per_check=1 order by per_nuber desc";

            }
            else
            ...{
  &nbsp;             sql = "select  top " + rowsPerPage.ToString() + " id,per_name,per_photoname,per_age,per_work,per_type,per_something,per_danwei,per_nuber from per_info  where per_check=1 and id not in (select top " + ((currentPage - 1) * rowsPerPage).ToString() + " id from per_info where per_check=1 order by per_nuber desc) order by per_nuber desc";
              
                //sql = "select top " + rowsPerPage.ToString() + " * from zuoyue_ask where ask_state=1 and id not in (select top " + ((currentPage - 1) * rowsPerPage).ToString() + " N_id from zuoyue_ask where N_id order by N_news_time desc) order by N_news_time desc";
            }
            DataSet ds = LiTianPing.DBUtility.DbHelperSQL.Query(sql);
            ds.Tables[0].Columns.Add("itmno");
            int rowcount = ds.Tables[0].Rows.Count;
            for (int i = 0; i < rowcount; i++)
            ...{
                ds.Tables[0].Rows[i]["itmno"] = i +((currentPage-1)*10) + 1; 
            }
           DataList1.DataSource = ds.Tables[0].DefaultVIEw;
           DataList1.DataBind();
        }

        //runTime.Text = DateTime.Now.TimeOfDay.Subtract(startTime).TotalMilliseconds.ToString();

        //conn.Close();
    }

  1. 上一頁:
  2. 下一頁:
Copyright © 程式師世界 All Rights Reserved