itemcommentcount.cs

来自「完全网站系统」· CS 代码 · 共 108 行

CS
108
字号
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 + =
减小字号Ctrl + -
显示快捷键?