⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 categorycheckboxlist.cs

📁 本系统是在asp版《在线文件管理器》的基础上设计制作
💻 CS
字号:
//------------------------------------------------------------------------------
// <copyright company="Telligent Systems">
//     Copyright (c) Telligent Systems Corporation.  All rights reserved.
// </copyright> 
//------------------------------------------------------------------------------

using System;
using System.Collections;
using System.ComponentModel;
using System.Globalization;
using System.Web.UI;
using System.Web.UI.WebControls;
using CommunityServer.Components;

namespace CommunityServer.Galleries.Controls
{
	/// <summary>
	/// Summary description for CategoryCheckBoxList.
	/// </summary>
	public class CategoryCheckBoxList : CheckBoxList, IRepeatInfoUser
	{

		#region Public Properties

		[DefaultValue( -1 )]
		public virtual int SectionID
		{
			get
			{
				Object state = ViewState["SectionID"];
				if(state != null)
					return (int)state;
				return -1;
			}
			set { ViewState["SectionID"] = value; }
		}

		#endregion

		public CategoryCheckBoxList()
		{
			this.controlToRepeat = new CheckBox();
			this.controlToRepeat.ID = "0";
			this.controlToRepeat.EnableViewState = false;
			this.Controls.Add(this.controlToRepeat);
		}

		public override void DataBind()
		{
			//throw new Exception("bah!");
				base.DataBind();
				Items.Clear();

				if(SectionID != -1)
					RecursiveAddCategories(0, PostCategories.GetCategories(SectionID, CategoryType.GalleryPicture, true, 0));
		}

		public void RecursiveAddCategories(int depth, ArrayList categories)
		{
			foreach(PostCategory category in categories)
			{
				ListItem item = new ListItem( category.Name, category.CategoryID.ToString() );
				item.Attributes.Add("depth", depth.ToString());
				Items.Add( item );
				
				ArrayList subCategories = PostCategories.GetCategories(category.SectionID, CategoryType.GalleryPicture, true, category.CategoryID);
				if(subCategories.Count > 0)
					RecursiveAddCategories(depth + 1, subCategories);
			}
		}

		protected override void OnPreRender(EventArgs e)
		{
			this.controlToRepeat.AutoPostBack = this.AutoPostBack;
			if(this.Page == null)
			{
				return;
			}
			for(int num1 = 0; num1 < this.Items.Count; num1++)
			{
				this.controlToRepeat.ID = num1.ToString(NumberFormatInfo.InvariantInfo);
				this.Page.RegisterRequiresPostBack(this.controlToRepeat);
			}
		}

		protected override void Render(HtmlTextWriter writer)
		{
			this.controlToRepeat.TabIndex = this.TabIndex;
			base.Render(writer);
		}


		private CheckBox controlToRepeat;
		void IRepeatInfoUser.RenderItem(ListItemType itemType, int repeatIndex, RepeatInfo repeatInfo, HtmlTextWriter writer)
		{
			controlToRepeat.ID = repeatIndex.ToString(NumberFormatInfo.InvariantInfo);
			controlToRepeat.Style.Add("margin-left", (1 * int.Parse(this.Items[repeatIndex].Attributes["depth"])) + "em");
			controlToRepeat.Text = this.Items[repeatIndex].Text;
			controlToRepeat.TextAlign = this.TextAlign;
			controlToRepeat.Checked = this.Items[repeatIndex].Selected;
			controlToRepeat.Enabled = this.Enabled;
			controlToRepeat.RenderControl(writer);
		}

	}
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -