zoukankan      html  css  js  c++  java
  • .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,这样才会把分页控件显示出来,呵呵……
    好了,慢慢研究吧
    我只是提供了最底层的方法而已,还有,补充一点,记得在此下载分页组件到你的工具栏里。

  • 相关阅读:
    使用mybatis如果类属性名和数据库中的属性名不一样取值就会为null
    学习mybatis时出现了java.io.IOException: Could not find resource EmployeeMapper.xml
    配置mybatis-config.xml出现过很诡异的现象
    mybatis学习(一)
    报错cannot be cast to javassist.util.proxy.Proxy
    列车调度
    三角形
    土豪聪要请客(stol)
    Jams倒酒(pour)
    Data
  • 原文地址:https://www.cnblogs.com/bbxie/p/568553.html
Copyright © 2011-2022 走看看