日期:2014-05-17  浏览次数:20559 次

请大侠帮忙:不用GridView和AspNetPager等控件,输出纯Div和CSS的分页,要怎么写?
ASPX页面的代码:
C# code

<div class="lst_box" id="divNewsList" runat="server"><!--文章列表--></div>
<div class="page"><a href="/NewsList_1.html">第一页</a><span class="NewsList_2.html">2</span><a href="NewsList_3.html">3</a>/div>



.CS的代码

C# code

    void bindData(string strSortID,string strNewsTitle)
    {
        if (ViewState["Sort"] == null)
            ViewState["Sort"] = "AddDate DESC";

        int TotalPage = 0;
        int TotalRecord = 0;
        int PageSize = 12;
        int CurrentPage = 1;
        //#region 循环分类
        DataTable dtBizClass = FrontPageBiz.GetPageNewsListByConditions(1,NewsSortID,SearchKeyWord, PageSize, ref CurrentPage, out TotalPage, out TotalRecord, (string)ViewState["Sort"]);


        for (int i = 1; i < dtBizClass.Rows.Count; i++)
        {
            divNewsList.Controls.Add(new LiteralControl("<div class=\"lstbox_m\"><h3><a href=\"/html/" + dtBizClass.Rows[i]["NewsID"].ToString() + ".html\">" + dtBizClass.Rows[i]["NewsTitle"].ToString() + "</a></h3><p class=\"more_big\">日期:" + string.Format("{0:d}", dtBizClass.Rows[i]["AddDate"]) + " 关注:100 <a href=\"#\">咨询专家</a></p> <p class=\"txt\">" + dtBizClass.Rows[i]["Descriptions"].ToString() + "</p></div>"));
        }



SQL:
SQL code

ALTER PROCEDURE [dbo].[XMLPageNewsListByCondition]
    (
    @vType int,
    @SortID varchar(12),
    @NewsTitle varchar(120),
    @PageSize int,
    @CurrentPage int output,
    @TotalPage int output,
    @TotalRecord int output,
    @SortBy varchar(100)
    )
AS



因为小弟以前一直是用Datalist和GridView+AspNetPager控件做后台分页,并带有搜索功能,现在想尝试下用div和css输出前台纯html的分页信息,但是分页做不出来,想请哪位大侠帮忙看看

------解决方案--------------------
看实际情况而定

看你的代码想要静态页分页,又像url重写。
前者比较纯粹,其实就是拼接字符串输出静态文件
后者,如果要纯粹,不用控件也是拼接字符串输出

附常规分页一份
C# code
    //-----分页所使用的变量
    private int num = 148;
    //在页面显示几条信息
    private int pageSize = 5;

    protected void Page_Load(object sender, EventArgs e)
    {
        //首次加载
        if (!IsPostBack)
        {
            DlBooksPage();
        }
    }



    /// <summary>
    /// 分页
    /// </summary>
    /// <param name="CurrentPage"></param>
    private void DataListBind(int CurrentPage)
    {

        int pageCount = this.BookNum();

        if (CurrentPage < 1)
        {
            CurrentPage = 1;
        }
        if (CurrentPage > pageCount)
        {
            CurrentPage = pageCount;
        }


        if (CurrentPage == 1)
        {
            this.btnPre.Enabled = false;
        }
        if (CurrentPage == pageCount)
        { this.btnNext.Enabled = false; }

        this.lblCurrentPage.Text = CurrentPage.ToString();
        this.lblPageCount.Text = pageCount.ToString();

        //DataSourceID 和 DataSource 不能并存,如果要 rptSearch.DataSource 起作用必须把 DataSourceID 赋为空
        if (dlBooks.DataSourceID != null)
        {
            dlBooks.DataSourceID = null;
        }

        //调用方法
        dlBooks.DataSource = BookManager.GetBooksByPageSize(this.GetKey(), pageSize, CurrentPage, this.Get