回覆列表
  • 1 # 陽光魯寧

    使用linq進行分頁,參考方法如下:

    protected void Page_Load(object sender, EventArgs e)

    {

    if (!IsPostBack)

    {

    int CurPage = 1;

    int PageSize = 5;

    int.TryParse(Request["CurPage"], out CurPage);

    if (CurPage == 0)

    CurPage = 1;

    //獲取總資料集合

    IList<ContentsModel> objs = new List<ContentsModel>();

    objs = Contents.GetAllContents();

    //繫結資料顯示控制元件

    GridView1.DataSource = QueryByPage(PageSize, CurPage, objs);

    GridView1.DataBind();

    //獲取分頁目錄

    this.Label1.Text = GetQueryPagesMenu(PageSize, objs);

    }

    }

    /// <summary>

    /// 輸入分頁字元頁碼

    /// </summary>

    /// <param name="PageSize"></param>

    /// <param name="objs"></param>

    /// <returns></returns>

    protected string GetQueryPagesMenu(int PageSize, IList<ContentsModel> objs)

    {

    int Count;

    var db = objs;

    var query = from cms_contents in db select cms_contents;

    Count = (query.Count() / PageSize + 1);//不足一頁按一頁算

    string PageMenu = "";

    //拼接分頁目錄

    for (int i = 1; i <= Count; i++)

    {

    }

    return PageMenu;

    }

    /// <summary>

    /// 獲

  • 中秋節和大豐收的關聯?
  • 是不是所有細菌都有莢膜和鞭毛?