Inheritance: System.Web.UI.Control, System.Web.UI.INamingContainer
Ejemplo n.º 1
0
//      /// <summary>
//      /// Called by the ASP.NET page framework to notify server controls that use composition-based implementation to create any child controls they contain in preparation for posting back or rendering.
//      /// </summary>
//		protected override void CreateChildControls()
//		{
//			if (ChildControlsCreated)
//			{
//				return;
//			}
//			Controls.Clear();
//
//			if (m_headerTemplate != null)
//			{
//				Control headerItem = new Control();
//				m_headerTemplate.InstantiateIn(headerItem);
//				Controls.Add(headerItem);
//			}
//
//			
//			if (m_footerTemplate != null)
//			{
//				Control footerItem = new Control();
//				m_footerTemplate.InstantiateIn(footerItem);
//				Controls.Add(footerItem);
//			}
//			ChildControlsCreated = true;
//		}
		
		/// <summary>
      /// Called by the ASP.NET page framework to notify server controls that use composition-based implementation to create any child controls they contain in preparation for posting back or rendering.
      /// </summary>
		protected override int CreateChildControls(System.Collections.IEnumerable dataSource, bool dataBinding)
      {
         int pos = 0;

         if (dataBinding)
         {
            //Instantiate the Header template (if exists)
            if (m_headerTemplate != null)
            {
                Control headerItem = new Control();
                m_headerTemplate.InstantiateIn(headerItem);
                Controls.Add(headerItem);
            }
			if (dataSource != null)
			{
				foreach (object o in dataSource)
				{
						Nettiers.AdventureWorks.Entities.VEmployee entity = o as Nettiers.AdventureWorks.Entities.VEmployee;
						VEmployeeItem container = new VEmployeeItem(entity);
	
						if (m_itemTemplate != null && (pos % 2) == 0)
						{
							m_itemTemplate.InstantiateIn(container);
							
							if (m_seperatorTemplate != null)
							{
								m_seperatorTemplate.InstantiateIn(container);
							}
						}
						else
						{
							if (m_altenateItemTemplate != null)
							{
								m_altenateItemTemplate.InstantiateIn(container);
								if (m_seperatorTemplate != null)
								{
									m_seperatorTemplate.InstantiateIn(container);
								}

							}
							else if (m_itemTemplate != null)
							{
								m_itemTemplate.InstantiateIn(container);
								if (m_seperatorTemplate != null)
								{
									m_seperatorTemplate.InstantiateIn(container);
								}

							}
							else
							{
								// no template !!!
							}
						}
						Controls.Add(container);
						
						container.DataBind();
						
						pos++;
				}
			}            
			//Instantiate the Footer template (if exists)
            if (m_footerTemplate != null)
            {
                Control footerItem = new Control();
                m_footerTemplate.InstantiateIn(footerItem);
                Controls.Add(footerItem);
            }				
		 }
			
			return pos;
		}
Ejemplo n.º 2
0
//      /// <summary>
//      /// Called by the ASP.NET page framework to notify server controls that use composition-based implementation to create any child controls they contain in preparation for posting back or rendering.
//      /// </summary>
//		protected override void CreateChildControls()
//		{
//			if (ChildControlsCreated)
//			{
//				return;
//			}
//			Controls.Clear();
//
//			if (m_headerTemplate != null)
//			{
//				Control headerItem = new Control();
//				m_headerTemplate.InstantiateIn(headerItem);
//				Controls.Add(headerItem);
//			}
//
//
//			if (m_footerTemplate != null)
//			{
//				Control footerItem = new Control();
//				m_footerTemplate.InstantiateIn(footerItem);
//				Controls.Add(footerItem);
//			}
//			ChildControlsCreated = true;
//		}

        /// <summary>
        /// Called by the ASP.NET page framework to notify server controls that use composition-based implementation to create any child controls they contain in preparation for posting back or rendering.
        /// </summary>
        protected override int CreateChildControls(System.Collections.IEnumerable dataSource, bool dataBinding)
        {
            int pos = 0;

            if (dataBinding)
            {
                //Instantiate the Header template (if exists)
                if (m_headerTemplate != null)
                {
                    Control headerItem = new Control();
                    m_headerTemplate.InstantiateIn(headerItem);
                    Controls.Add(headerItem);
                }
                if (dataSource != null)
                {
                    foreach (object o in dataSource)
                    {
                        Nettiers.AdventureWorks.Entities.VEmployee entity = o as Nettiers.AdventureWorks.Entities.VEmployee;
                        VEmployeeItem container = new VEmployeeItem(entity);

                        if (m_itemTemplate != null && (pos % 2) == 0)
                        {
                            m_itemTemplate.InstantiateIn(container);

                            if (m_seperatorTemplate != null)
                            {
                                m_seperatorTemplate.InstantiateIn(container);
                            }
                        }
                        else
                        {
                            if (m_altenateItemTemplate != null)
                            {
                                m_altenateItemTemplate.InstantiateIn(container);
                                if (m_seperatorTemplate != null)
                                {
                                    m_seperatorTemplate.InstantiateIn(container);
                                }
                            }
                            else if (m_itemTemplate != null)
                            {
                                m_itemTemplate.InstantiateIn(container);
                                if (m_seperatorTemplate != null)
                                {
                                    m_seperatorTemplate.InstantiateIn(container);
                                }
                            }
                            else
                            {
                                // no template !!!
                            }
                        }
                        Controls.Add(container);

                        container.DataBind();

                        pos++;
                    }
                }
                //Instantiate the Footer template (if exists)
                if (m_footerTemplate != null)
                {
                    Control footerItem = new Control();
                    m_footerTemplate.InstantiateIn(footerItem);
                    Controls.Add(footerItem);
                }
            }

            return(pos);
        }