📄 topic.cs
字号:
namespace ASPNET.StarterKit.Communities {
using System;
using System.Web.UI;
using System.Web.UI.WebControls;
using ASPNET.StarterKit.Communities;
//*********************************************************************
//
// Topic Class
//
// Represents the topic page. This class
// displays a list of article listings.
//
// _skinFileName = the name of the skin to use for this section
//
// _getContentItems = the name of the method that retrieves the list of content items
//
//*********************************************************************
public class Topic : ContentListPage {
string _skinFileName = "Topics_Topic.ascx";
GetContentItemsDelegate _getContentItems = new GetContentItemsDelegate(TopicUtility.GetTopicContent);
Image imgTopicImage;
Label lblTopicTitle;
Label lblTopicDescription;
private TopicInfo objTopicInfo;
//*********************************************************************
//
// TopicID Property
//
// Stores the ID of the current topic in view state
//
//*********************************************************************
int TopicID {
get { return (int)ViewState["TopicID"]; }
set { ViewState["TopicID"] = value; }
}
//*********************************************************************
//
// InitializeSkin Method
//
// Retrieves all the controls from the Page Skin
//
//*********************************************************************
void SkinLoadTopic(Object s, SkinLoadEventArgs e) {
// Find Topic Image
imgTopicImage = (Image)GetControl(e.Skin, "TopicImage");
// Find Topic Title
lblTopicTitle = (Label)GetControl(e.Skin, "TopicTitle");
// Find Topic Description
lblTopicDescription = (Label)GetControl(e.Skin, "TopicDescription");
}
//*********************************************************************
//
// OnInit Method
//
// Here we check whether a topic was passed in a query string.
//
//*********************************************************************
protected override void OnInit(EventArgs e) {
if (!Page.IsPostBack) {
// If no topic, go home
if (Context.Request.QueryString["Topic"] == null)
Context.Response.Redirect("~/Default.aspx");
}
}
//*********************************************************************
//
// OnLoad Method
//
// Handles the Page Load event in order to initialize the current page
// by assigning values to the controls.
//
//*********************************************************************
protected override void OnLoad(EventArgs e) {
if (!Page.IsPostBack) {
string _topicName = Context.Request.QueryString["Topic"];
// Get TopicInfo
objTopicInfo = TopicUtility.GetTopicFromName(_topicName);
// Store topicID in view state
TopicID = objTopicInfo.ID;
// Get total records
TotalRecords = TopicUtility.GetTotalRecords(TopicID);
// Create the controls
EnsureChildControls();
// Display Topic Image
if (objTopicInfo.Image != String.Empty)
imgTopicImage.ImageUrl = Page.ResolveUrl(objTopicInfo.Image);
else
imgTopicImage.Visible = false;
// Display Topic Title
lblTopicTitle.Text = objTopicInfo.Name;
// Display Topic Description
lblTopicDescription.Text = objTopicInfo.Description;
}
}
override protected void BindContent() {
objContentList.DataSource = GetContentItems(objUserInfo.Username, TopicID, objSectionInfo.RecordsPerPage, objContentList.CurrentPage, SortOrder);
objContentList.DataBind();
}
//*********************************************************************
//
// Topic Constructor
//
// Assigns skin and contentItems method to base ContentListPage class
//
//*********************************************************************
public Topic() : base() {
SkinFileName = _skinFileName;
GetContentItems = _getContentItems;
// Wire-up event handlers
this.SkinLoad += new SkinLoadEventHandler(SkinLoadTopic);
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -