dictionarylister.cs

来自「东软内部材料(四)asp等相关的教学案例 」· CS 代码 · 共 67 行

CS
67
字号
using System;
using System.Web;
using System.Web.UI;
using System.Collections;
using System.Web.UI.WebControls;

namespace WroxControls 
{

   public class ICollectionLister : WebControl, INamingContainer
											        // Step 3
   {

		ICollection _datasource;


		public ICollection DataSource
		{
			get { return _datasource; }
			set { _datasource = value; }
		}

		Style _headingStyle = new Style();

		public Style HeadingStyle
		{
			get{ return _headingStyle; }
		}

		Style _itemStyle = new Style();

		public Style ItemStyle
		{
			get{ return _itemStyle; }
		}

      protected override void CreateChildControls()
      {
			IEnumerator e;
			Label l;

			// Create the heading, using the specified user style

			l = new Label();
			l.ApplyStyle( _headingStyle );
			l.Text = "ICollection Lister Control";
			Controls.Add( l );

			// Create an label for each key/value pair in the collection

			if ( _datasource == null )
				throw new Exception("Control requires a data source");

			e = _datasource.GetEnumerator();

			while( e.MoveNext() )
			{
				l = new Label();
				l.ApplyStyle( _itemStyle );
				l.Text = "<BR>" + e.Current.ToString();
				Controls.Add( l );
			}
		}
   }
};

⌨️ 快捷键说明

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