asp.net2005+javascript+SqlServer2000

爱她就要好好地呵护她

 

.net2005中GridView或者Datalist等超級流行的分頁

像人民網,新浪網那樣,分頁即好看又好用!
我也自己下載了一個組件,添加到工具欄后,拖到設計視圖,然後添加簡單的代碼就可以用了
擧個例子吧:
 /// <summary>
    /// 新聞邦定
    /// </summary>
    public void newsBind()
    {
        string strCon = "Database=cnrenmai;server=.;uid=sa;pwd=;";
        SqlConnection con = new SqlConnection(strCon);
        con.Open();
        string strCom = "select * from articles where userID=39 order by artDate desc";
        SqlDataAdapter da = new SqlDataAdapter(strCom, con);
        DataSet ds = new DataSet("art");
        SqlCommand comm = new SqlCommand("select count(*) from articles where userID=39", con);

        //=================對AspNetPager1進行設置========================
        this.AspNetPager1.RecordCount = int.Parse(comm.ExecuteScalar().ToString());
        int repeatestr1 = AspNetPager1.PageSize * (AspNetPager1.CurrentPageIndex - 1);
        int repeatestr2 = AspNetPager1.PageSize;
        da.Fill(ds, repeatestr1, repeatestr2, "art");
        this.GridView1.DataSource = ds.Tables["art"].DefaultView;
        this.GridView1.DataBind();
        con.Close();    
        //动态设置用户自定义文本内容
        AspNetPager1.CustomInfoText = "记录总数:<b>" + AspNetPager1.RecordCount.ToString() + "</b>";
        AspNetPager1.CustomInfoText += " 总页数:<b>" + AspNetPager1.PageCount.ToString() + "</b>";
        AspNetPager1.CustomInfoText += " 当前页:<font color=\"red\"><b>" + AspNetPager1.CurrentPageIndex.ToString() + "</b></font>";
    }

    /// <summary>
    /// 分頁函數
    /// </summary>
    /// <param name="src"></param>
    /// <param name="e"></param>
    protected void AspNetPager1_PageChanged(object src, Wuqi.Webdiyer.PageChangedEventArgs e)
    {
        AspNetPager1.CurrentPageIndex = e.NewPageIndex;
        currentpage = e.NewPageIndex;
        this.newsBind();//新聞邦定函數
    }

另外,這個AspNetPager1的很多属性要进行修改,譬如最关键的“AlwaysShow”属性,要设置为True,这样才会把分页控件显示出来,呵呵……
好了,慢慢研究吧
我只是提供了最底层的方法而已,还有,补充一点,记得在此下载分页组件到你的工具栏里。

posted on 2006-11-22 13:04  g無s所p畏   阅读(589)  评论(1编辑  收藏  举报

导航