Asp.NETPersonnalBlogSystem/Default.aspx.cs

(开头部分) 1KB

这里只显示每个文件的开头 60 行。登录后可以解锁完整代码。

using System;
using System.Collections.Generic;
using Asp.NETPersonnalBlogSystem.BLL;
using Asp.NETPersonnalBlogSystem.Models;

namespace Asp.NETPersonnalBlogSystem
{
    /// <summary>
    /// 网站首页
    /// 显示文章列表,支持分页
    /// </summary>
    public partial class _Default : System.Web.UI.Page
    {
        private int pageIndex = 1;
        private int pageSize = 10;
        private ArticleService articleService = new ArticleService();
        private SettingService settingService = new SettingService();

        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                if (!int.TryParse(Request.QueryString["page"], out pageIndex))
                {
                    pageIndex = 1;
                }

                pageSize = Convert.ToInt32(settingService.GetSetting("ArticlePageSize", "10"));
                LoadArticles();
            }
        }

        /// <summary>
        /// 加载文章列表
        /// </summary>
        private void LoadArticles()
        {
            List<Article> articles = articleService.GetArticleList(pageIndex, pageSize, 0, "", 1);
            int totalCount = articleService.GetArticleCount(0, "", 1);
            int totalPages = (int)Math.Ceiling((double)totalCount / pageSize);

            rptArticles.DataSource = articles;
            rptArticles.DataBind();

            litCurrentPage.Text = pageIndex.ToString();
            litTotalPages.Text = totalPages.ToString();

            liPrev.Visible = pageIndex > 1;
            liNext.Visible = pageIndex < totalPages;
        }

        protected void btnPrev_Click(object sender, EventArgs e)
        {
            Response.Redirect($"Default.aspx?page={pageIndex - 1}");
        }

        protected void btnNext_Click(object sender, EventArgs e)
        {
            Response.Redirect($"Default.aspx?page={pageIndex + 1}");
        }
后面还有 2 行代码,解锁后查看完整代码

24 小时内免费解锁 3 个项目,之后 1 算力/个。 规则说明

AI 解读 AI

登录后可用,每次 10 算力,解读结果公开显示在下面。

还没有人解读过这个文件。