📄 forumrepeater.cs
字号:
} else {
img.ImageUrl = Globals.ApplicationVRoot + "/skins/" + SiteStyle + "/images/forum_status.gif";
}
}
}
}
// *********************************************************************
// BeginBuildItemTemplate
//
/// <summary>
/// Builds a default Item template if the user does not specify one
/// </summary>
///
// ********************************************************************/
public virtual Control BeginBuildItemTemplate() {
Label label;
PlaceHolder placeHolder = new PlaceHolder();
TableCell td;
TableRow tr = new TableRow();
// Column 1
td = new TableCell();
td.CssClass = "forumRow";
td.HorizontalAlign = HorizontalAlign.Center;
td.Width = 34;
td.Wrap = false;
Image img = new Image();
img.Width = 34;
img.DataBinding += new System.EventHandler(HandleDataBindingForStatusImage);
td.Controls.Add(img);
tr.Controls.Add(td);
// Column 2
td = new TableCell();
td.CssClass = "forumRow";
td.Width = Unit.Percentage(80);
HyperLink link = new HyperLink();
link.CssClass = "forumTitle";
link.DataBinding += new System.EventHandler(HandleDataBindingForForumTitle);
Label forumDescription = new Label();
forumDescription.CssClass = "normalTextSmall";
forumDescription.DataBinding += new System.EventHandler(HandleDataBindingForForumDescription);
td.Controls.Add(link);
td.Controls.Add(new LiteralControl("<BR>"));
td.Controls.Add(forumDescription);
tr.Controls.Add(td);
// Column 3
td = new TableCell();
td.HorizontalAlign = HorizontalAlign.Center;
td.CssClass = "forumRowHighlight";
td.DataBinding += new System.EventHandler(HandleDataBindingForTotalThreads);
tr.Controls.Add(td);
// Column 4
td = new TableCell();
td.HorizontalAlign = HorizontalAlign.Center;
td.CssClass = "forumRowHighlight";
td.DataBinding += new System.EventHandler(HandleDataBindingForTotalPosts);
tr.Controls.Add(td);
// Column 5
td = new TableCell();
td.HorizontalAlign = HorizontalAlign.Center;
td.CssClass = "forumRowHighlight";
Label mostRecentPostDate = new Label();
mostRecentPostDate.CssClass = "normalTextSmaller";
mostRecentPostDate.DataBinding += new System.EventHandler(HandleDataBindingForMostRecentPost);
label = new Label();
label.CssClass = "normalTextSmaller";
label.DataBinding += new System.EventHandler(HandleDataBindingForPostedBy);
td.Controls.Add(mostRecentPostDate);
td.Controls.Add(new LiteralControl("<BR>"));
td.Controls.Add(label);
tr.Controls.Add(td);
// Add the Table Row
placeHolder.Controls.Add(tr);
return placeHolder;
}
// *********************************************************************
// BuildItemTemplate
//
/// <summary>
/// Template builder for the ItemTemplate
/// </summary>
///
// ********************************************************************/
private void BuildItemTemplate(Control _ctrl) {
// add the DataBoundLiteralControl to the parser
System.Web.UI.IParserAccessor __parser = ((System.Web.UI.IParserAccessor)(_ctrl));
__parser.AddParsedSubObject(BeginBuildItemTemplate());
}
// *********************************************************************
// CreateChildControls
//
/// <summary>
/// Override create child controls
/// </summary>
///
// ********************************************************************/
protected override void CreateChildControls() {
EnableViewState = false;
string username = null;
// determine if we want to bind to the default template or not
ApplyTemplates();
if (ForumUser != null)
username = ForumUser.Username;
// bind the datalist to the SqlDataReader returned by the GetAllForums() method
ForumCollection forums;
Forums f = new Forums();
try {
if (ForumGroupID == 0) {
if (showAllForums)
forums = Forums.GetAllForums(true, username);
else
forums = Forums.GetAllForums(false, username);
forums.Sort();
DataSource = forums;
} else {
if (showAllForums)
DataSource = f.GetForumsByForumGroupId(ForumGroupID, username, true);
else
DataSource = f.GetForumsByForumGroupId(ForumGroupID, username);
}
} catch (Components.ForumNotFoundException fnf) {
Page.Response.Redirect(Globals.UrlMessage + Convert.ToInt32(Messages.UnknownForum));
Page.Response.End();
}
this.DataBind();
}
// *********************************************************************
// ApplyTemplates
//
/// <summary>
/// Applies templates to control the ui generated by the control. If no
/// template is specified a custom template is used. If a template is found
/// in the skins directory, that template is loaded and used. If a user defined
/// template is found, that template takes priority.
/// </summary>
///
// ********************************************************************/
public virtual void ApplyTemplates() {
string pathToHeaderTemplate;
string pathToItemTemplate;
string pathToAlternatingItemTemplate;
string pathToFooterTemplate;
string keyForHeaderTemplate;
string keyForItemTemplate;
string keyForAlternatingItemTemplate;
string keyForFooterTemplate;
// Are we using skinned template?
if (Page != null) {
// Set the file paths to where the templates should be found
pathToHeaderTemplate = Globals.ApplicationVRoot + "/Skins/" + SiteStyle + "/Templates/ForumRepeater-Header.ascx";
pathToItemTemplate = Globals.ApplicationVRoot + "/skins/" + SiteStyle + "/Templates/ForumRepeater-Item.ascx";
pathToAlternatingItemTemplate = Globals.ApplicationVRoot + "/skins/" + SiteStyle + "/Templates/ForumRepeater-AlternatingItem.ascx";
pathToFooterTemplate = Globals.ApplicationVRoot + "/skins/" + SiteStyle + "/Templates/ForumRepeater-Footer.ascx";
// Set the file paths to where the templates should be found
keyForHeaderTemplate = SiteStyle + "/Templates/ForumRepeater-Header.ascx";
keyForItemTemplate = SiteStyle + "/Templates/ForumRepeater-Item.ascx";
keyForAlternatingItemTemplate = SiteStyle + "/Templates/ForumRepeater-AlternatingItem.ascx";
keyForFooterTemplate = SiteStyle + "/Templates/ForumRepeater-Footer.ascx";
// Attempt to get the skinned header template
if (HeaderTemplate == null)
HeaderTemplate = Globals.LoadSkinnedTemplate(pathToHeaderTemplate, keyForHeaderTemplate, Page);
// Attempt to get the skinned item template
if (ItemTemplate == null)
ItemTemplate = Globals.LoadSkinnedTemplate(pathToItemTemplate,keyForItemTemplate, Page);
// Attempt to get the skinned item template
if (AlternatingItemTemplate == null)
AlternatingItemTemplate = Globals.LoadSkinnedTemplate(pathToAlternatingItemTemplate,keyForAlternatingItemTemplate, Page);
// Attempt to get the footer template
if (FooterTemplate == null)
FooterTemplate = Globals.LoadSkinnedTemplate(pathToFooterTemplate, keyForFooterTemplate, Page);
}
// No skinned or user defined template, load the default
if (ItemTemplate == null)
ItemTemplate = new CompiledTemplateBuilder(new BuildTemplateMethod(BuildItemTemplate));
}
// *********************************************************************
// ShowAllForums
//
/// <summary>
/// Returns forums that are not active - however, will not return forums that
/// the user's credentials do not have permissions to.
/// </summary>
///
// ********************************************************************/
public bool ShowAllForums {
get { return showAllForums; }
set { showAllForums = value; }
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -