📄 itemcommentlink.cs
字号:
namespace ASPNET.StarterKit.Communities {
using System;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.ComponentModel;
//*********************************************************************
//
// ItemCommentLink Class
//
// Represents the number of comments and displays a link to the content
// page.
//
//*********************************************************************
public class ItemCommentLink : WebControl {
private string _formatText = "{0} comments Add/View";
//*********************************************************************
//
// ItemCommentLink Constructor
//
// Adds a default cascading style sheet style
//
//*********************************************************************
public ItemCommentLink () : base(HtmlTextWriterTag.A) {
CssClass = "itemCommentLink";
EnableViewState = false;
}
//*********************************************************************
//
// FormatText Property
//
// Text formatting applied to comment
//
//*********************************************************************
public string FormatText {
get { return _formatText; }
set { _formatText = value;}
}
//*********************************************************************
//
// OnDataBinding Method
//
// Get the comment count and contentpageID 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;
ViewState["ContentPageID"] = objContentInfo.ContentPageID;
}
//*********************************************************************
//
// 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);
}
//*********************************************************************
//
// AddAttributesToRender Method
//
// Add the HRef that links to the profile page
//
//*********************************************************************
protected override void AddAttributesToRender(HtmlTextWriter writer) {
string _link = CommunityGlobals.CalculatePath(String.Format("{0}.aspx", ViewState["ContentPageID"]));
writer.AddAttribute(HtmlTextWriterAttribute.Href, _link);
}
//*********************************************************************
//
// RenderContents Method
//
// Write the formatted 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 + -