Click here to Skip to main content
15,893,487 members
Articles / Web Development / ASP.NET

Web User Forms for ASP.NET

Rate me:
Please Sign up or sign in to vote.
4.90/5 (52 votes)
18 Sep 2012CPOL12 min read 135.6K   4.5K   187  
User driven runtime dynamic ASP.NET Web Forms
// -- FILE ------------------------------------------------------------------
// name       : UserFormCollection.cs
// project    : Itenso Web User Forms
// created    : Jani Giannoudis - 2008.10.30
// language   : c#
// environment: .NET 2.0
// copyright  : (c) 2008-2012 by Itenso GmbH, Switzerland
// --------------------------------------------------------------------------
using System;
using System.Collections;
using System.Collections.Generic;

namespace Itenso.WebUserForms.Controls
{

	// ------------------------------------------------------------------------
	public class UserFormCollection : IUserFormCollection
	{

		// ----------------------------------------------------------------------
		public int Count
		{
			get { return forms.Count; }
		} // Count

		// ----------------------------------------------------------------------
		public IUserForm this[ int index ]
		{
			get { return forms[ index ]; }
		} // this[]

		// ----------------------------------------------------------------------
		public IEnumerator<IUserForm> GetEnumerator()
		{
			return forms.GetEnumerator();
		} // GetEnumerator

		// ----------------------------------------------------------------------
		IEnumerator IEnumerable.GetEnumerator()
		{
			return forms.GetEnumerator();
		} // IEnumerable.GetEnumerator


		// ----------------------------------------------------------------------
		public int IndexOf( IUserForm form )
		{
			return forms.IndexOf( form );
		} // IndexOf

		// ----------------------------------------------------------------------
		public IUserForm FindByFormName( string formName )
		{
			foreach ( IUserForm form in forms )
			{
				if ( form.Header.Name.Equals( formName ) )
				{
					return form;
				}
			}
			return null;
		} // FindByFormName

		// ----------------------------------------------------------------------
		public int Add( IUserForm form )
		{
			if ( form == null )
			{
				throw new ArgumentNullException( "form" );
			}
			int insertPos = forms.Count;
			forms.Add( form );
			return insertPos;
		} // Add

		// ----------------------------------------------------------------------
		public void Add( IUserForm form, int pos )
		{
			forms.Insert( pos, form );
		} // Add

		// ----------------------------------------------------------------------
		public void AddAll( IEnumerable<IUserForm> items )
		{
			if ( items == null )
			{
				throw new ArgumentNullException( "items" );
			}
			foreach ( IUserForm item in items )
			{
				Add( item );
			}
		} // AddAll

		// ----------------------------------------------------------------------
		public void Remove( IUserForm item )
		{
			forms.Remove( item );
		} // Remove

		// ----------------------------------------------------------------------
		public void RemoveAt( int index )
		{
			forms.RemoveAt( index );
		} // RemoveAt

		// ----------------------------------------------------------------------
		public void Clear()
		{
			forms.Clear();
		} // Clear

		// ----------------------------------------------------------------------
		public IUserForm[] ToArray()
		{
			IUserForm[] entries = new IUserForm[ Count ];
			if ( entries.Length > 0 )
			{
				CopyTo( entries, 0 );
			}
			return entries;
		} // ToArray

		// ----------------------------------------------------------------------
		public void CopyTo( IUserForm[] array, int index )
		{
			forms.CopyTo( array, index );
		} // CopyTo

		// ----------------------------------------------------------------------
		// members
		private readonly List<IUserForm> forms = new List<IUserForm>();

	} // class UserFormCollection

} // namespace Itenso.WebUserForms.Controls
// -- EOF -------------------------------------------------------------------

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Software Developer (Senior)
Switzerland Switzerland
👨 Senior .NET Software Engineer

🚀 My Open Source Projects
- Time Period Library 👉 GitHub
- Payroll Engine 👉 GitHub

Feedback and contributions are welcome.



Comments and Discussions