📄 webboxlist.cs
字号:
namespace ASPNET.StarterKit.Communities {
using System;
using System.Web.UI;
using System.Web.UI.WebControls;
using ASPNET.StarterKit.Communities.Services;
using System.Web.Security;
using System.Collections;
//*********************************************************************
//
// WebBoxList Class
//
// Displays a list of Web box controls.
//
//*********************************************************************
public class WebBoxList : SkinnedCommunityControl {
string _skinFileName = "WebBoxes_WebBoxList.ascx";
DataList dlstWebBoxes;
//*********************************************************************
//
// WebBoxList Constructor
//
// Calls the base SkinnedCommunityControl constructor
// and assigns the default page skin.
//
//*********************************************************************
public WebBoxList() : base() {
// Assign a default skin file name
if (SkinFileName == null)
SkinFileName = _skinFileName;
}
//*********************************************************************
//
// SkinType Property
//
// Specifies the skins directory where this page's skin file is located.
//
//*********************************************************************
override protected string SkinType {
get { return "ControlSkins"; }
}
//*********************************************************************
//
// InitializeSkin Method
//
// Retrieves all the controls from the Page Skin
//
//*********************************************************************
override protected void InitializeSkin(Control skin) {
// Find Web Boxes repeater
dlstWebBoxes = (DataList)GetControl(skin, "dlstWebBoxes");
dlstWebBoxes.ItemDataBound += new DataListItemEventHandler(Boxes_ItemDataBound);
}
//*********************************************************************
//
// OnLoad Method
//
// Handles the Page Load event in order to initialize the current page
// by assigning values to the controls.
//
//*********************************************************************
override protected void OnLoad(EventArgs e) {
EnsureChildControls();
if (objSectionInfo.WebBoxes.Length > 0) {
dlstWebBoxes.DataSource = CalculateWebBoxes(objSectionInfo.WebBoxes);
dlstWebBoxes.DataBind();
}
}
//*********************************************************************
//
// Boxes_ItemDataBound Method
//
// Assigns values to the controls contained in the item and
// alternating item templates of the Repeater used to display
// the list of Web boxes.
//
//*********************************************************************
void Boxes_ItemDataBound(Object s, DataListItemEventArgs e) {
// Don't do any binding in header or footer
if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem) {
// Get the box name
string boxName = (string)e.Item.DataItem;
// Find the place holder
PlaceHolder placeHolder = (PlaceHolder)GetControl(e.Item, "plhWebBox");
try {
// Load the control
Control box = Page.LoadControl(WebBoxUtility.GetWebBoxPath(boxName));
// Add control to PlaceHolder
placeHolder.Controls.Add(box);
} catch (Exception ex) {
ActivityUtility.RecordError("Could not find Web Box", ex);
}
}
}
//*********************************************************************
//
// CalculateWebBoxes Method
//
// Determines which Web boxes to display based on the
// WebBoxDisplayMode property.
//
//*********************************************************************
private ArrayList CalculateWebBoxes(string[] webBoxes) {
int intItem = 0;
ArrayList colArrayList = new ArrayList(webBoxes);
// show all
if (objSectionInfo.WebBoxDisplayMode == 0)
return colArrayList;
// Calculate number of boxes to display
int displayCount = Math.Min(objSectionInfo.WebBoxDisplayMode, colArrayList.Count);
// Get correct number of WebBoxes
Random objRan = new Random();
ArrayList colNewArrayList = new ArrayList();
for (int i=0;i<displayCount;i++) {
intItem = objRan.Next(colArrayList.Count);
colNewArrayList.Add(colArrayList[intItem]);
colArrayList.RemoveAt(intItem);
}
return colNewArrayList;
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -