using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;

namespace UsingServerControls
{
	/// <summary>
	/// Summary description for multipleSelection.
	/// </summary>
	public class multipleSelection : System.Web.UI.Page
	{
		protected System.Web.UI.HtmlControls.HtmlSelect Select1;
		protected System.Web.UI.WebControls.Label Selection;
		protected System.Web.UI.HtmlControls.HtmlInputButton SelectBtn;
	
		private void Page_Load(object sender, System.EventArgs e)
		{
			// Put user code to initialize the page here
			this.Select1.Multiple = true;
		}

		#region Web Form Designer generated code
		override protected void OnInit(EventArgs e)
		{
			//
			// CODEGEN: This call is required by the ASP.NET Web Form Designer.
			//
			InitializeComponent();
			base.OnInit(e);
		}
		
		/// <summary>
		/// Required method for Designer support - do not modify
		/// the contents of this method with the code editor.
		/// </summary>
		private void InitializeComponent()
		{    
			this.SelectBtn.ServerClick += new System.EventHandler(this.SelectBtn_ServerClick);
			this.Load += new System.EventHandler(this.Page_Load);

		}
		#endregion

		private void SelectBtn_ServerClick(object sender, System.EventArgs e)
		{
			System.Text.StringBuilder msg = new System.Text.StringBuilder();
			int count = 0;
			// build the selection string
			foreach (ListItem item in this.Select1.Items)
			{
				// add the selected item
				if (true == item.Selected)
				{
					if (0 != count)
						msg.Append(',');				

					msg.Append(item.Text);
					count++;
				}
			}
			if (msg.Length > 0)
			{
				msg.Insert(0, "You've selected: ");
				this.Selection.Text = msg.ToString();
			}
		}
	}
}
