页面没有数据控件,所有数据都在dataset里面,页面输出用for循环,请问能用aspnetpager实现分页不?如果可以,该如何做?

解决方案 »

  1.   

    我愿意洗耳恭听,您可以发邮件到[email protected],我自己观摩研究
      

  2.   


           /// <summary>
           /// 获取记录数
           /// </summary>
           /// <param name="table"></param>
           /// <param name="cond">格式:Where ...</param>
           /// <returns></returns>
           public int GetRowCount(string table, string cond)
           {
               
               string query = string.Format("Select count(*) From {0} {1}", table, cond);
               DataSet ds = db.GetDataSet(query);
               if (ds != null)
               {
                   if (ds.Tables.Count > 0 && ds.Tables[0].Rows.Count > 0)
                   {
                       return Galsun.Common.Utils.StrToInt(ds.Tables[0].Rows[0][0].ToString(), 0);
                   }
               }
               return 0;       }
           /// <summary>
           /// 
           /// </summary>
           /// <param name="table"></param>
           /// <param name="rowpage"></param>
           /// <param name="rowcount"></param>
           /// <param name="orderFid"></param>
           /// <param name="Conditions"></param>
           /// <returns></returns>
           public DataSet GetinfoList(string table, int rowpage, int rowcount, string orderFid, string Conditions)
           {           string query = "Select * From "
                   + "(Select *,ROW_NUMBER() OVER(ORDER BY {2}) as RowNum From {4} {3}) as newTable "
                   + "Where (RowNum BETWEEN ({0}) AND ({1}))";
               query = string.Format(query, (rowpage - 1) * rowcount + 1, rowpage * rowcount, orderFid, Conditions, table);           //string query = "Select top {0} * From {1} {2} and id not in(Select top {3} id From {1} {2} Order by {4}) Order by {4}";
               //query = string.Format(query, rowcount, table, Conditions, (rowpage - 1) * rowcount + 1, orderFid);
               return db.GetDataSet(query);       }
    //应用都是一样的    protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                bindData();
            }
        }
        void bindData()
        {        string cond = " Where isCheck=1 and sid=2 "; //初使化一个SQL语句str        //绑定数据
            AspNetPager1.RecordCount = GetRowCount("gl_NewsSystem", cond);
            DataTable dt = GetinfoList("gl_NewsSystem", AspNetPager1.CurrentPageIndex, AspNetPager1.PageSize, " OrderID DESC,FBDate DESC,id DESC", cond);
            foreach(DataRow item in dt.Rows)
            {
              .......
            }
        }
        protected void AspNetPager1_PageChanged(object sender, EventArgs e)
        {
            bindData();//更新页面数据
        }
      

  3.   


     public void Bind()
            {
                int Top = 0;
                string strWhere = " IsTrue=1 and Type=5  ";
                string filedOrder = "Time desc";
                BLL.BOOK book = new BLL.BOOK();
                DataSet set = new DataSet();
                set = book.GetList(Top, strWhere, filedOrder);
                int pagesize = AspNetPager1.PageSize;
                int currentpage = AspNetPager1.CurrentPageIndex;
                imd = book.GetListTo(Top, strWhere, filedOrder, pagesize * (currentpage - 1), pagesize);            AspNetPager1.RecordCount = set.Tables[0].Rows.Count;
            }
      

  4.   

    这是我自己写的一个还不错的分页事件!!!book.GetListTo()就是分页,看看da.Fill()方法就知道了