⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 itemcommentcount.cs

📁 ASP开发网站的 关于网站的设计和说明 还有SQL的程序 数据库
💻 CS
字号:
namespace ASPNET.StarterKit.Communities {
    using System;
    using System.Web;
    using System.Web.UI;
    using System.Web.UI.WebControls;
    using System.ComponentModel;




    //*********************************************************************
    //
    // ItemCommentCount Class
    //
    // Represents the number of comments 
    //
    //*********************************************************************

    public class ItemCommentCount : WebControl {

        string _formatText = "{0} comments";
    
    

        //*********************************************************************
        //
        // ItemCommentCount Constructor
        //
        // Assign a default cascading style class
        //
        //*********************************************************************
    
        public ItemCommentCount () : base() {
            CssClass = "ItemCommentCount";
            EnableViewState = false;
        }


        //*********************************************************************
        //
        // FormatText Property
        //
        // Determines the formatting of the comment
        //
        //*********************************************************************

        public string FormatText {
            get { return _formatText; }
            set { _formatText = value; }
        }



        //*********************************************************************
        //
        // OnDataBinding Method
        //
        // Get the comment info from context
        //
        //*********************************************************************

        override protected void OnDataBinding(EventArgs e) {
            ContentItem item;

            if (NamingContainer is ContentItem)
                item = (ContentItem)NamingContainer;
            else
                item = (ContentItem)NamingContainer.NamingContainer;


            ContentInfo objContentInfo = (ContentInfo)item.DataItem;
            ViewState["CommentCount"] = objContentInfo.CommentCount;
        }



        //*********************************************************************
        //
        // Render Method
        //
        // Only render if comments are enabled
        //
        //*********************************************************************

        override protected void Render(HtmlTextWriter writer) {
            SectionInfo objSectionInfo = (SectionInfo)HttpContext.Current.Items["SectionInfo"];
            if (objSectionInfo.EnableComments)
                base.Render(writer);
        }


        //*********************************************************************
        //
        // RenderContents Method
        //
        // Render the comment count
        //
        //*********************************************************************

        override protected void RenderContents(HtmlTextWriter writer) {

            writer.Write(String.Format(_formatText, ViewState["CommentCount"]));    
        }


    }
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -