toolbardropdownlist.cs

来自「该项目中对 SQLHelper 类进行了简单封装」· CS 代码 · 共 113 行

CS
113
字号
/* 
 * ToolbarDropDownList.cs @Microsoft Visual Studio 2008 <.NET Framework 3.5>
 * AfritXia
 * 2006-07-20
 * 
 * Copyright(c) http://www.AfritXia.NET/
 * 
 */

using System;
using System.Collections;
using System.Collections.Specialized;
using System.Text;
using System.Web;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;

namespace NET.AfritXia.Components.Web.TextPane
{
	/// <summary>
	/// 工具条下拉列表框
	/// </summary>
	internal class ToolbarDropDownList : System.Web.UI.HtmlControls.HtmlSelect, INamingContainer, IClientRunTime
	{
		// 命令名称
		private string m_commandName = "CMD_EMPTY";

		#region 类 ToolbarDropDownList 构造器
		/// <summary>
		/// 类 ToolbarDropDownList 默认构造器
		/// </summary>
		protected ToolbarDropDownList()
			: base()
		{
		}

		/// <summary>
		/// 类 ToolbarDropDownList 参数构造器
		/// </summary>
		/// <param name="commandName">命令名称</param>
		protected ToolbarDropDownList(string commandName)
			: this()
		{
			if (commandName != null && commandName != "")
				this.m_commandName = commandName;
		}
		#endregion

		/// <summary>
		/// 获取命令名称
		/// </summary>
		public string CommandName
		{
			get
			{
				return this.m_commandName;
			}
		}

		/// <summary>
		/// 设置或获取选择值
		/// </summary>
		public string SelectedValue
		{
			set
			{
				foreach (ListItem item in this.Items)
					item.Selected = (item.Value == value);
			}

			get
			{
				if (this.Items == null || this.Items.Count <= 0)
					return null;

				return this.Items[this.SelectedIndex].Value;
			}
		}

		/// <summary>
		/// 在绘制控件之前,添加控件属性
		/// </summary>
		protected override void OnPreRender(EventArgs e)
		{
			base.OnPreRender(e);

			// 添加 CSS 样式表属性
			this.Attributes.Add("class", "CToolbarDropDownList");

			// 添加控件在客户端的加载事件
			this.Attributes.Add("onload",
				string.Format("javascript: new CToolbarDropDownList(this);", this.CommandName));
		}

		/// <summary>
		/// 建立工具条下拉列表框
		/// </summary>
		/// <param name="commandName">命令名称</param>
		/// <returns></returns>
		public static ToolbarDropDownList Create(string commandName)
		{
			return new ToolbarDropDownList(commandName);
		}

		#region IClientRunTime 成员
		public string CreateJavaScriptObject()
		{
			return string.Format("new CToolbarDropDownList('{0}', '{1}');", this.UniqueID, this.CommandName);
		}
		#endregion
	}
}

⌨️ 快捷键说明

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