comboboxdesigner.cs

来自「ASP中web自定义控件的使用源码及说明文档」· CS 代码 · 共 53 行

CS
53
字号
using System;
using System.IO;
using System.Web.UI;
using System.Web.UI.Design;
using System.Web.UI.WebControls;
using System.Web.UI.Design.WebControls;

namespace Bestcomy.Web.UI.WebControls
{
	/// <summary>
	/// 
	/// </summary>
	public class ComboBoxDesigner : ControlDesigner
	{
		private ComboBox comboBox;

		public ComboBoxDesigner()
		{
		}

		public override void Initialize(System.ComponentModel.IComponent component)
		{
			base.Initialize (component);
			this.comboBox = (ComboBox)component;
		}


		public override string GetDesignTimeHtml()
		{
			DropDownList drop = new  DropDownList();
			if(this.comboBox.Items.Count > 0)
			{
				foreach(ComboItem item in comboBox.Items)
				{
					ListItem litem = new ListItem(item.Text,item.Text);
					if(item.Selected)
						litem.Selected = true;
					drop.Items.Add(litem);
				}
			}
			else
			{
				drop.Items.Add(new ListItem("Unbound"));
			}
			drop.Width = comboBox.Width;
			StringWriter sw = new StringWriter();
			HtmlTextWriter tw = new HtmlTextWriter(sw);
			drop.RenderControl(tw);
			return sw.ToString();
		}
	}
}

⌨️ 快捷键说明

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