Access 分页的那些碎事儿

功能:

      使用AspnetPager控件 绑定给 GridView 分页。数据库为 Access

详细分析:

      1、准备控件,GridView,AspnetPager。

  2、调整AspnetPager样式。

      3、后台写一个分页方法。

      4、在页面首次加载的时候调用此方法。

  5、在Aspnetpager的 AspNetPager_PageChanged 事件中设定页码,再次调用分页方法。

  6、分页方法剖析:

          Access:   T-Sql语句   分页方法如下:

      

 public static IList<_P_Category> FillSmallPager(int pagesize,int start)
    {
        string s_p=string.Empty;
        if (start == 0)
        {
            s_p = string.Format
            ("select c_id,c_name from XWE_P_Category ");
        }
        else
        {
            s_p = string.Format
            ("select top {0} c_id,c_name from XWE_P_Category where (c_id not in (select top 2 c_id from  XWE_P_Category))"
            , pagesize, start);
        }
        
        IList<_P_Category> list = new List<_P_Category>();
        _P_Category _p_c = null;
        DataTable dt = SaleInfoManager.GetBySQL(s_p);
        foreach (DataRow dr in dt.Rows)
        {
            _p_c = new _P_Category();
            _p_c.C_id = (int)dr["c_id"];
            _p_c.C_name = (string)dr["c_name"];
            list.Add(_p_c);
        }
        return list;
    }

   7、窗体加载时调用绑定 Gridview的方法:

  

protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
typeList();
AspNetPager1.RecordCount
= count;
}
}

  

  8、GridView的绑定方法:

private void typeList()
{
int start = AspNetPager1.PageSize * (AspNetPager1.CurrentPageIndex-1);//获得开始页
int pagesize = AspNetPager1.PageSize ;//总页数

IList
<BigTypeModel> list = typeDal.GetList(pagesize, start, "");//获得结果

count
= typeDal.getCount();//得到数据的总行数,用于给分页的总数量赋值

this.gvBigtype.DataSource = list;
this.gvBigtype.DataBind();

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>";
}

  9、AspnetPager的 页码改变事件:

protected void AspNetPager1_PageChanged(object src, Wuqi.Webdiyer.PageChangedEventArgs e)
{
AspNetPager1.CurrentPageIndex
=e.NewPageIndex;
typeList();
}

效果:

原文地址:https://www.cnblogs.com/307914070/p/1956954.html