コード例 #1
0
        protected void Page_Load(object sender, EventArgs e)
        {
            #region 绑定content
            string      newsid   = Context.Request.QueryString["newsid"];
            List <News> newsList = new NewsBll().GetModelList("");
            if (string.IsNullOrWhiteSpace(newsid))
            {
                newsid = newsList[0].NewsId.ToString();
            }
            if (!newsid.IsNumber())
            {
                newsid = newsList[0].NewsId.ToString();
            }
            bool isExists = newsList.Exists(o => o.NewsId == Convert.ToInt32(newsid));
            if (!isExists)
            {
                newsid = newsList[0].NewsId.ToString();
            }
            List <Model.News> list     = new NewsBll().GetModelList("Status=1", "UpdateDate desc");
            Model.News        news     = list.SingleOrDefault(o => o.NewsId == Convert.ToInt32(newsid));
            Model.News        preNews  = GetPreNews(list, news);
            Model.News        nextNews = GetNextNews(list, news);
            if (string.IsNullOrWhiteSpace(newsid))
            {
                content = "newsid未接收到";
                return;
            }
            StringBuilder sb = new StringBuilder();
            sb.Append("<div class='content'>");
            sb.Append("<div class='title'>");
            sb.AppendFormat("<h3>{0}</h3>", news.Title);
            sb.Append("</div>");
            sb.AppendFormat("<div class='infos'>{0}&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;点击:{1}<script language='javascript' src='/inc/article_view.asp?id=938'></script></div>", news.UpdateDate, news.Click);
            sb.Append("<div class='maincontent clearfix'>");
            sb.Append("<div id='MainContent' class='maincontent clearfix'>");
            sb.AppendFormat("{0}", news.Content);
            sb.Append("</div>");
            sb.Append("</div>");
            sb.Append("<div class='prenext'>");
            sb.Append("<ul>");
            if (preNews == null)
            {
                sb.AppendFormat("<li>上一篇:没有了</li>");
            }
            else
            {
                sb.AppendFormat("<li>上一篇:<a href='{0}' target='_blank' title='{1}'>{1}</a> <span class='ListDate'>{2}</span></li>", "/newsPage/newsContent.aspx?newsid=" + preNews.NewsId, preNews.Title, preNews.UpdateDate.ToShortDateString());
            }
            if (nextNews == null)
            {
                sb.AppendFormat("<li>下一篇:没有了</li>");
            }
            else
            {
                sb.AppendFormat("<li>下一篇:<a href='{0}' target='_blank' title='{1}'>{1}</a> <span class='ListDate'>{2}</span></li>", "/newsPage/newsContent.aspx?newsid=" + nextNews.NewsId, nextNews.Title, nextNews.UpdateDate.ToShortDateString());
            }

            sb.Append("</ul>");
            sb.Append("</div>");
            sb.Append("</div>");

            content = sb.ToString();
            #endregion
        }