首页 新闻 会员 周边 捐助

关于自定义控件的数据绑定

0
悬赏园豆:5 [已解决问题] 解决于 2013-03-26 11:49

我的希望我的DataSource属性为一个List<T>类型的数据,然后指定一个TextField和一个ValueField,然后我解析成我需要的数据。就像.net 自带的那些控件一样。考虑到了序列化和反射,但是序列化的实用性不高,反射的话不知道如何下手。有没有个参考代码啥的,或者一个新的思路啥的

< >
分享
最佳答案
0

想办法看.net的源码吧。。。

收获园豆:5
顾晓北 | 专家六级 |园豆:10898 | 2013-03-21 10:56

- -  劳烦您给指一条明路

动感超人z | 园豆:1 (初学一级) | 2013-03-21 11:14

@枼秋: 你不是想做跟。net控件差不多的功能么?那就看这个控件的源码啊。用reflector之类的。。。

顾晓北 | 园豆:10898 (专家六级) | 2013-03-21 15:00

@顾晓北: 工具下载了,挺好用,我正在找哪个工具箱的类库在哪里呢,还想看看有没有别的意见的。顺便问下晓北兄你知道我要找的类库在哪里么

动感超人z | 园豆:1 (初学一级) | 2013-03-21 17:22

@枼秋: 自己搜一搜.netframework装在什么文件夹吧。

顾晓北 | 园豆:10898 (专家六级) | 2013-03-22 09:57

@顾晓北: - - 我觉得这个能看到的可能性怎么比较低呢。

话说我自己用反射写好了一个方法

 private string SwitchToJson<T>(IList<T> li, string Text, string Value) where T : class
{
//body
}
//这是我的数据源属性
public Object DataSource{get;set;}

好吧这个

SwitchToJson的方法该怎么调用呢?
//如果我这样写肯定是报错的,类型不一致
//好吧!!  我真心第一次写反射
//这玩意一般怎么写呢 
SwitchToJson(DataSource,DataValue,DataText)
动感超人z | 园豆:1 (初学一级) | 2013-03-22 14:21

@枼秋: 怎么调用?你不是写自定义控件么?当然是在控件里面调用啊。

顾晓北 | 园豆:10898 (专家六级) | 2013-03-22 16:06

@顾晓北: 我的意思是我的这个方法需要传进来的参数是List<T>,而我的DataSource是object类型的(传因为这个属性的类型是没有办法确定的,所以选择了object),我怎么把DataSource传进这个方法里面去呢

动感超人z | 园豆:1 (初学一级) | 2013-03-22 18:02

@枼秋: 

// Generated by .NET Reflector from C:\Windows\assembly\GAC_32\System.Web\2.0.0.0__b03f5f7f11d50a3a\System.Web.dll
namespace System.Web.UI
{
    using System;
    using System.Collections;
    using System.Collections.Specialized;
    using System.ComponentModel;
    using System.ComponentModel.Design.Serialization;
    using System.Globalization;
    using System.IO;
    using System.Runtime.InteropServices;
    using System.Security.Permissions;
    using System.Web;
    using System.Web.Caching;
    using System.Web.Configuration;
    using System.Web.Hosting;
    using System.Web.UI.Adapters;
    using System.Web.UI.WebControls;
    using System.Web.Util;
    
    [ToolboxItem("System.Web.UI.Design.WebControlToolboxItem, System.Design, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"), DesignerCategory("Code"), Bindable(true), DefaultProperty("ID"), DesignerSerializer("Microsoft.VisualStudio.Web.WebForms.ControlCodeDomSerializer, Microsoft.VisualStudio.Web, Version=8.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a", "System.ComponentModel.Design.Serialization.CodeDomSerializer, System.Design, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"), ToolboxItemFilter("System.Web.UI", ToolboxItemFilterType.Require), Designer("System.Web.UI.Design.ControlDesigner, System.Design, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"), Themeable(false), AspNetHostingPermission(SecurityAction.InheritanceDemand, Level=AspNetHostingPermissionLevel.Minimal), AspNetHostingPermission(SecurityAction.LinkDemand, Level=AspNetHostingPermissionLevel.Minimal)]
    public class Control : IComponent, IDisposable, IParserAccessor, IUrlResolutionService, IDataBindingsAccessor, IControlBuilderAccessor, IControlDesignerAccessor, IExpressionsAccessor
    {
        internal ControlAdapter _adapter;
        private string _cachedUniqueID;
        private System.Web.UI.ControlState _controlState;
        private string _id;
        private Control _namingContainer;
        private OccasionalFields _occasionalFields;
        internal System.Web.UI.Page _page;
        private Control _parent;
        private System.Web.UI.TemplateControl _templateControl;
        private VirtualPath _templateSourceVirtualDirectory;
        private StateBag _viewState;
        private const int automaticIDCount = 0x80;
        private const string automaticIDPrefix = "ctl";
        private static readonly string[] automaticIDs = new string[] { 
            "ctl00", "ctl01", "ctl02", "ctl03", "ctl04", "ctl05", "ctl06", "ctl07", "ctl08", "ctl09", "ctl10", "ctl11", "ctl12", "ctl13", "ctl14", "ctl15", 
            "ctl16", "ctl17", "ctl18", "ctl19", "ctl20", "ctl21", "ctl22", "ctl23", "ctl24", "ctl25", "ctl26", "ctl27", "ctl28", "ctl29", "ctl30", "ctl31", 
            "ctl32", "ctl33", "ctl34", "ctl35", "ctl36", "ctl37", "ctl38", "ctl39", "ctl40", "ctl41", "ctl42", "ctl43", "ctl44", "ctl45", "ctl46", "ctl47", 
            "ctl48", "ctl49", "ctl50", "ctl51", "ctl52", "ctl53", "ctl54", "ctl55", "ctl56", "ctl57", "ctl58", "ctl59", "ctl60", "ctl61", "ctl62", "ctl63", 
            "ctl64", "ctl65", "ctl66", "ctl67", "ctl68", "ctl69", "ctl70", "ctl71", "ctl72", "ctl73", "ctl74", "ctl75", "ctl76", "ctl77", "ctl78", "ctl79", 
            "ctl80", "ctl81", "ctl82", "ctl83", "ctl84", "ctl85", "ctl86", "ctl87", "ctl88", "ctl89", "ctl90", "ctl91", "ctl92", "ctl93", "ctl94", "ctl95", 
            "ctl96", "ctl97", "ctl98", "ctl99", "ctl100", "ctl101", "ctl102", "ctl103", "ctl104", "ctl105", "ctl106", "ctl107", "ctl108", "ctl109", "ctl110", "ctl111", 
            "ctl112", "ctl113", "ctl114", "ctl115", "ctl116", "ctl117", "ctl118", "ctl119", "ctl120", "ctl121", "ctl122", "ctl123", "ctl124", "ctl125", "ctl126", "ctl127"
         };
        private const string automaticLegacyIDPrefix = "_ctl";
        private const int controlAdapterResolved = 0x8000;
        private const int controlsCreated = 8;
        private const int controlStateApplied = 0x100000;
        private const int creatingControls = 0x100;
        private const int designMode = 0x10000;
        private const int designModeChecked = 0x20000;
        private const int disableChildControlState = 0x40000;
        private const int disableTheming = 0x1000;
        private const int disableViewState = 4;
        private const int enableThemingSet = 0x2000;
        internal const bool EnableViewStateDefault = true;
        internal static readonly object EventDataBinding = new object();
        private static readonly object EventDisposed = new object();
        internal static readonly object EventInit = new object();
        internal static readonly object EventLoad = new object();
        internal static readonly object EventPreRender = new object();
        internal static readonly object EventUnload = new object();
        internal SimpleBitVector32 flags;
        private const char ID_RENDER_SEPARATOR = '_';
        internal const char ID_SEPARATOR = '$';
        private const int idNotCalculated = 1;
        private const int idNotRequired = 0x40;
        private const int invisible = 0x10;
        private const int isNamingContainer = 0x80;
        internal const int isWebControlDisabled = 0x80000;
        internal const char LEGACY_ID_SEPARATOR = ':';
        private const int marked = 2;
        private const int mustRenderID = 0x800;
        private const int notVisibleOnPage = 0x200;
        private const int styleSheetApplied = 0x4000;
        private const int themeApplied = 0x400;
        private const int useGeneratedID = 0x200000;
        private const int visibleDirty = 0x20;
        
        [WebSysDescription("Control_OnDataBind"), WebCategory("Data")]
        public event EventHandler DataBinding
        {
            add
            {
                this.Events.AddHandler(EventDataBinding, value);
            }
            remove
            {
                this.Events.RemoveHandler(EventDataBinding, value);
            }
        }
        
        [WebSysDescription("Control_OnDisposed")]
        public event EventHandler Disposed
        {
            add
            {
                this.Events.AddHandler(EventDisposed, value);
            }
            remove
            {
                this.Events.RemoveHandler(EventDisposed, value);
            }
        }
        
        [WebSysDescription("Control_OnInit")]
        public event EventHandler Init
        {
            add
            {
                this.Events.AddHandler(EventInit, value);
            }
            remove
            {
                this.Events.RemoveHandler(EventInit, value);
            }
        }
        
        [WebSysDescription("Control_OnLoad")]
        public event EventHandler Load
        {
            add
            {
                this.Events.AddHandler(EventLoad, value);
            }
            remove
            {
                this.Events.RemoveHandler(EventLoad, value);
            }
        }
        
        [WebSysDescription("Control_OnPreRender")]
        public event EventHandler PreRender
        {
            add
            {
                this.Events.AddHandler(EventPreRender, value);
            }
            remove
            {
                this.Events.RemoveHandler(EventPreRender, value);
            }
        }
        
        [WebSysDescription("Control_OnUnload")]
        public event EventHandler Unload
        {
            add
            {
                this.Events.AddHandler(EventUnload, value);
            }
            remove
            {
                this.Events.RemoveHandler(EventUnload, value);
            }
        }
        
        public Control()
        {
            if (this is INamingContainer)
            {
                this.flags.Set(0x80);
            }
        }
        
        protected internal virtual void AddedControl(Control control, int index)
        {
            if (control.OwnerControl != null)
            {
                throw new InvalidOperationException(System.Web.SR.GetString("Substitution_NotAllowed"));
            }
            if (control._parent != null)
            {
                control._parent.Controls.Remove(control);
            }
            control._parent = this;
            control._page = this.Page;
            control.flags.Clear(0x20000);
            Control namingContainer = this.flags[0x80] ? this : this._namingContainer;
            if (namingContainer != null)
            {
                control.UpdateNamingContainer(namingContainer);
                if ((control._id == null) && !control.flags[0x40])
                {
                    control.GenerateAutomaticID();
                }
                else if ((control._id != null) || ((control._occasionalFields != null) && (control._occasionalFields.Controls != null)))
                {
                    namingContainer.DirtyNameTable();
                }
            }
            if (this._controlState >= System.Web.UI.ControlState.ChildrenInitialized)
            {
                control.InitRecursive(namingContainer);
                if (((control._controlState >= System.Web.UI.ControlState.Initialized) && (control.RareFields != null)) && control.RareFields.RequiredControlState)
                {
                    this.Page.RegisterRequiresControlState(control);
                }
                if (this._controlState >= System.Web.UI.ControlState.ViewStateLoaded)
                {
                    object savedState = null;
                    if ((this._occasionalFields != null) && (this._occasionalFields.ControlsViewState != null))
                    {
                        savedState = this._occasionalFields.ControlsViewState[index];
                        if (this.LoadViewStateByID)
                        {
                            control.EnsureID();
                            savedState = this._occasionalFields.ControlsViewState[control.ID];
                            this._occasionalFields.ControlsViewState.Remove(control.ID);
                        }
                        else
                        {
                            savedState = this._occasionalFields.ControlsViewState[index];
                            this._occasionalFields.ControlsViewState.Remove(index);
                        }
                    }
                    control.LoadViewStateRecursive(savedState);
                    if (this._controlState >= System.Web.UI.ControlState.Loaded)
                    {
                        control.LoadRecursive();
                        if (this._controlState >= System.Web.UI.ControlState.PreRendered)
                        {
                            control.PreRenderRecursiveInternal();
                        }
                    }
                }
            }
        }
        
        protected virtual void AddParsedSubObject(object obj)
        {
            Control child = obj as Control;
            if (child != null)
            {
                this.Controls.Add(child);
            }
        }
        
        private void ApplySkin(System.Web.UI.Page page)
        {
            if (page == null)
            {
                throw new ArgumentNullException("page");
            }
            if (!this.flags[0x400] && ThemeableAttribute.IsTypeThemeable(base.GetType()))
            {
                page.ApplyControlSkin(this);
                this.flags.Set(0x400);
            }
        }
        
        [EditorBrowsable(EditorBrowsableState.Advanced)]
        public virtual void ApplyStyleSheetSkin(System.Web.UI.Page page)
        {
            if (page != null)
            {
                if (this.flags[0x4000])
                {
                    throw new InvalidOperationException(System.Web.SR.GetString("StyleSheetAreadyAppliedOnControl"));
                }
                if (page.ApplyControlStyleSheet(this))
                {
                    this.flags.Set(0x4000);
                }
            }
        }
        
        protected void BuildProfileTree(string parentId, bool calcViewState)
        {
            int num;
            calcViewState = calcViewState && !this.flags[4];
            if (calcViewState)
            {
                num = this.EstimateStateSize(this.SaveViewState());
            }
            else
            {
                num = 0;
            }
            int controlStateSize = 0;
            if (((this.Page != null) && (this.Page._registeredControlsRequiringControlState != null)) && this.Page._registeredControlsRequiringControlState.Contains(this))
            {
                controlStateSize = this.EstimateStateSize(this.SaveControlStateInternal());
            }
            this.Page.Trace.AddNewControl(this.UniqueID, parentId, base.GetType().FullName, num, controlStateSize);
            if ((this._occasionalFields != null) && (this._occasionalFields.Controls != null))
            {
                int count = this._occasionalFields.Controls.Count;
                for (int i = 0; i < count; i++)
                {
                    this._occasionalFields.Controls[i].BuildProfileTree(this.UniqueID, calcViewState);
                }
            }
        }
        
        private void ClearCachedUniqueIDRecursive()
        {
            this._cachedUniqueID = null;
            if (this._occasionalFields != null)
            {
                this._occasionalFields.UniqueIDPrefix = null;
                if (this._occasionalFields.Controls != null)
                {
                    int count = this._occasionalFields.Controls.Count;
                    for (int i = 0; i < count; i++)
                    {
                        this._occasionalFields.Controls[i].ClearCachedUniqueIDRecursive();
                    }
                }
            }
        }
        
        protected void ClearChildControlState()
        {
            if (this.ControlState >= System.Web.UI.ControlState.Initialized)
            {
                this.flags.Set(0x40000);
                if (this.Page != null)
                {
                    this.Page.RegisterRequiresClearChildControlState(this);
                }
            }
        }
        
        protected void ClearChildState()
        {
            this.ClearChildControlState();
            this.ClearChildViewState();
        }
        
        protected void ClearChildViewState()
        {
            if (this._occasionalFields != null)
            {
                this._occasionalFields.ControlsViewState = null;
            }
        }
        
        internal void ClearNamingContainer()
        {
            this.EnsureOccasionalFields();
            this._occasionalFields.NamedControlsID = 0;
            this.DirtyNameTable();
        }
        
        protected internal virtual void CreateChildControls()
        {
        }
        
        protected virtual ControlCollection CreateControlCollection()
        {
            return new ControlCollection(this);
        }
        
        public virtual void DataBind()
        {
            this.DataBind(true);
        }
        
        protected virtual void DataBind(bool raiseOnDataBinding)
        {
            bool flag = false;
            if (this.IsBindingContainer)
            {
                bool flag2;
                object dataItem = DataBinder.GetDataItem(this, out flag2);
                if (flag2 && (this.Page != null))
                {
                    this.Page.PushDataBindingContext(dataItem);
                    flag = true;
                }
            }
            try
            {
                if (raiseOnDataBinding)
                {
                    this.OnDataBinding(EventArgs.Empty);
                }
                this.DataBindChildren();
            }
            finally
            {
                if (flag)
                {
                    this.Page.PopDataBindingContext();
                }
            }
        }
        
        protected virtual void DataBindChildren()
        {
            if (this.HasControls())
            {
                this.EnsureOccasionalFields();
                string errorMsg = this._occasionalFields.Controls.SetCollectionReadOnly("Parent_collections_readonly");
                try
                {
                    try
                    {
                        int count = this._occasionalFields.Controls.Count;
                        for (int i = 0; i < count; i++)
                        {
                            this._occasionalFields.Controls[i].DataBind();
                        }
                    }
                    finally
                    {
                        this._occasionalFields.Controls.SetCollectionReadOnly(errorMsg);
                    }
                }
                catch
                {
                    throw;
                }
            }
        }
        
        internal void DirtyNameTable()
        {
            if (this._occasionalFields != null)
            {
                this._occasionalFields.NamedControls = null;
            }
        }
        
        public virtual void Dispose()
        {
            IContainer service = null;
            if (this.Site != null)
            {
                service = (IContainer) this.Site.GetService(typeof(IContainer));
                if (service != null)
                {
                    service.Remove(this);
                    EventHandler handler = this.Events[EventDisposed] as EventHandler;
                    if (handler != null)
                    {
                        handler(this, EventArgs.Empty);
                    }
                }
            }
            if (this._occasionalFields != null)
            {
                this._occasionalFields.Dispose();
            }
        }
        
        protected virtual void EnsureChildControls()
        {
            if (!this.ChildControlsCreated && !this.flags[0x100])
            {
                this.flags.Set(0x100);
                try
                {
                    this.ResolveAdapter();
                    if (this._adapter != null)
                    {
                        this._adapter.CreateChildControls();
                    }
                    else
                    {
                        this.CreateChildControls();
                    }
                    this.ChildControlsCreated = true;
                }
                finally
                {
                    this.flags.Clear(0x100);
                }
            }
        }
        
        protected void EnsureID()
        {
            if (this._namingContainer != null)
            {
                if (this._id == null)
                {
                    this.GenerateAutomaticID();
                }
                this.flags.Set(0x800);
            }
        }
        
        private void EnsureNamedControlsTable()
        {
            this._occasionalFields.NamedControls = new HybridDictionary(this._occasionalFields.NamedControlsID, true);
            this.FillNamedControlsTable(this, this._occasionalFields.Controls);
        }
        
        private void EnsureOccasionalFields()
        {
            if (this._occasionalFields == null)
            {
                this._occasionalFields = new OccasionalFields();
            }
        }
        
        internal int EstimateStateSize(object state)
        {
            if (state == null)
            {
                return 0;
            }
            return Util.SerializeWithAssert(new ObjectStateFormatter(), state).Length;
        }
        
        private void FillNamedControlsTable(Control namingContainer, ControlCollection controls)
        {
            int count = controls.Count;
            for (int i = 0; i < count; i++)
            {
                Control control = controls[i];
                if (control._id != null)
                {
                    try
                    {
                        namingContainer.EnsureOccasionalFields();
                        namingContainer._occasionalFields.NamedControls.Add(control._id, control);
                    }
                    catch
                    {
                        throw new HttpException(System.Web.SR.GetString("Duplicate_id_used", new object[] { control._id, "FindControl" }));
                    }
                }
                if (control.HasControls() && !control.flags[0x80])
                {
                    this.FillNamedControlsTable(namingContainer, control.Controls);
                }
            }
        }
        
        public virtual Control FindControl(string id)
        {
            return this.FindControl(id, 0);
        }
        
        protected virtual Control FindControl(string id, int pathOffset)
        {
            string str;
            this.EnsureChildControls();
            if (!this.flags[0x80])
            {
                Control namingContainer = this.NamingContainer;
                if (namingContainer != null)
                {
                    return namingContainer.FindControl(id, pathOffset);
                }
                return null;
            }
            if (this.HasControls() && (this._occasionalFields.NamedControls == null))
            {
                this.EnsureNamedControlsTable();
            }
            if ((this._occasionalFields == null) || (this._occasionalFields.NamedControls == null))
            {
                return null;
            }
            char[] anyOf = new char[] { '$', ':' };
            int num = id.IndexOfAny(anyOf, pathOffset);
            if (num == -1)
            {
                str = id.Substring(pathOffset);
                return (this._occasionalFields.NamedControls[str] as Control);
            }
            str = id.Substring(pathOffset, num - pathOffset);
            Control control2 = this._occasionalFields.NamedControls[str] as Control;
            if (control2 == null)
            {
                return null;
            }
            return control2.FindControl(id, num + 1);
        }
        
        public virtual void Focus()
        {
            this.Page.SetFocus(this);
        }
        
        private void GenerateAutomaticID()
        {
            this.flags.Set(0x200000);
            this._namingContainer.EnsureOccasionalFields();
            int index = this._namingContainer._occasionalFields.NamedControlsID++;
            if (this.EnableLegacyRendering)
            {
                this._id = "_ctl" + index.ToString(NumberFormatInfo.InvariantInfo);
            }
            else if (index < 0x80)
            {
                this._id = automaticIDs[index];
            }
            else
            {
                this._id = "ctl" + index.ToString(NumberFormatInfo.InvariantInfo);
            }
            this._namingContainer.DirtyNameTable();
        }
        
        [SecurityPermission(SecurityAction.Demand, Unrestricted=true)]
        protected virtual IDictionary GetDesignModeState()
        {
            ControlRareFields rareFieldsEnsured = this.RareFieldsEnsured;
            if (rareFieldsEnsured.DesignModeState == null)
            {
                rareFieldsEnsured.DesignModeState = new HybridDictionary();
            }
            return rareFieldsEnsured.DesignModeState;
        }
        
        internal virtual System.Web.UI.TemplateControl GetTemplateControl()
        {
            if ((this._templateControl == null) && (this.Parent != null))
            {
                this._templateControl = this.Parent.GetTemplateControl();
            }
            return this._templateControl;
        }
        
        internal virtual string GetUniqueIDPrefix()
        {
            this.EnsureOccasionalFields();
            if (this._occasionalFields.UniqueIDPrefix == null)
            {
                string uniqueID = this.UniqueID;
                if (!string.IsNullOrEmpty(uniqueID))
                {
                    this._occasionalFields.UniqueIDPrefix = uniqueID + this.IdSeparator;
                }
                else
                {
                    this._occasionalFields.UniqueIDPrefix = string.Empty;
                }
            }
            return this._occasionalFields.UniqueIDPrefix;
        }
        
        internal XhtmlConformanceSection GetXhtmlConformanceSection()
        {
            HttpContext context = this.Context;
            if (context != null)
            {
                return RuntimeConfig.GetConfig(context).XhtmlConformance;
            }
            return RuntimeConfig.GetConfig().XhtmlConformance;
        }
        
        public virtual bool HasControls()
        {
            return (((this._occasionalFields != null) && (this._occasionalFields.Controls != null)) && (this._occasionalFields.Controls.Count > 0));
        }
        
        protected bool HasEvents()
        {
            return ((this._occasionalFields != null) && (this._occasionalFields.Events != null));
        }
        
        internal bool HasRenderDelegate()
        {
            return ((this.RareFields != null) && (this.RareFields.RenderMethod != null));
        }
        
        internal bool HasRenderingData()
        {
            if (!this.HasControls())
            {
                return this.HasRenderDelegate();
            }
            return true;
        }
        
        internal virtual void InitRecursive(Control namingContainer)
        {
            this.ResolveAdapter();
            if ((this._occasionalFields != null) && (this._occasionalFields.Controls != null))
            {
                if (this.flags[0x80])
                {
                    namingContainer = this;
                }
                string errorMsg = this._occasionalFields.Controls.SetCollectionReadOnly("Parent_collections_readonly");
                int count = this._occasionalFields.Controls.Count;
                for (int i = 0; i < count; i++)
                {
                    Control control = this._occasionalFields.Controls[i];
                    control.UpdateNamingContainer(namingContainer);
                    if (((control._id == null) && (namingContainer != null)) && !control.flags[0x40])
                    {
                        control.GenerateAutomaticID();
                    }
                    control._page = this.Page;
                    control.InitRecursive(namingContainer);
                }
                this._occasionalFields.Controls.SetCollectionReadOnly(errorMsg);
            }
            if (this._controlState < System.Web.UI.ControlState.Initialized)
            {
                this._controlState = System.Web.UI.ControlState.ChildrenInitialized;
                if (((this.Page != null) && !this.DesignMode) && (this.Page.ContainsTheme && this.EnableTheming))
                {
                    this.ApplySkin(this.Page);
                }
                if (this._adapter != null)
                {
                    this._adapter.OnInit(EventArgs.Empty);
                }
                else
                {
                    this.OnInit(EventArgs.Empty);
                }
                this._controlState = System.Web.UI.ControlState.Initialized;
            }
            this.TrackViewState();
        }
        
        internal bool IsDescendentOf(Control ancestor)
        {
            Control parent = this;
            while ((parent != ancestor) && (parent.Parent != null))
            {
                parent = parent.Parent;
            }
            return (parent == ancestor);
        }
        
        protected bool IsLiteralContent()
        {
            return ((((this._occasionalFields != null) && (this._occasionalFields.Controls != null)) && (this._occasionalFields.Controls.Count == 1)) && (this._occasionalFields.Controls[0] is LiteralControl));
        }
        
        internal void LoadChildViewStateByID(ArrayList childState)
        {
            int count = childState.Count;
            for (int i = 0; i < count; i += 2)
            {
                string id = (string) childState[i];
                object savedState = childState[i + 1];
                Control control = this.FindControl(id);
                if (control != null)
                {
                    control.LoadViewStateRecursive(savedState);
                }
                else
                {
                    this.EnsureOccasionalFields();
                    if (this._occasionalFields.ControlsViewState == null)
                    {
                        this._occasionalFields.ControlsViewState = new Hashtable();
                    }
                    this._occasionalFields.ControlsViewState[id] = savedState;
                }
            }
        }
        
        internal void LoadChildViewStateByIndex(ArrayList childState)
        {
            ControlCollection controls = this.Controls;
            int count = controls.Count;
            int num2 = childState.Count;
            for (int i = 0; i < num2; i += 2)
            {
                int num4 = (int) childState[i];
                object savedState = childState[i + 1];
                if (num4 < count)
                {
                    controls[num4].LoadViewStateRecursive(savedState);
                }
                else
                {
                    this.EnsureOccasionalFields();
                    if (this._occasionalFields.ControlsViewState == null)
                    {
                        this._occasionalFields.ControlsViewState = new Hashtable();
                    }
                    this._occasionalFields.ControlsViewState[num4] = savedState;
                }
            }
        }
        
        protected internal virtual void LoadControlState(object savedState)
        {
        }
        
        internal void LoadControlStateInternal(object savedStateObj)
        {
            if (!this.flags[0x100000])
            {
                this.flags.Set(0x100000);
                Pair pair = (Pair) savedStateObj;
                if (pair != null)
                {
                    System.Web.UI.Page page = this.Page;
                    if ((page == null) || page.ShouldLoadControlState(this))
                    {
                        if (pair.First != null)
                        {
                            this.LoadControlState(pair.First);
                        }
                        if ((this._adapter != null) && (pair.Second != null))
                        {
                            this._adapter.LoadAdapterControlState(pair.Second);
                        }
                    }
                }
            }
        }
        
        internal virtual void LoadRecursive()
        {
            if (this._controlState < System.Web.UI.ControlState.Loaded)
            {
                if (this._adapter != null)
                {
                    this._adapter.OnLoad(EventArgs.Empty);
                }
                else
                {
                    this.OnLoad(EventArgs.Empty);
                }
            }
            if ((this._occasionalFields != null) && (this._occasionalFields.Controls != null))
            {
                string errorMsg = this._occasionalFields.Controls.SetCollectionReadOnly("Parent_collections_readonly");
                int count = this._occasionalFields.Controls.Count;
                for (int i = 0; i < count; i++)
                {
                    this._occasionalFields.Controls[i].LoadRecursive();
                }
                this._occasionalFields.Controls.SetCollectionReadOnly(errorMsg);
            }
            if (this._controlState < System.Web.UI.ControlState.Loaded)
            {
                this._controlState = System.Web.UI.ControlState.Loaded;
            }
        }
        
        protected virtual void LoadViewState(object savedState)
        {
            if (savedState != null)
            {
                this.ViewState.LoadViewState(savedState);
                object obj2 = this.ViewState["Visible"];
                if (obj2 != null)
                {
                    if (!((bool) obj2))
                    {
                        this.flags.Set(0x10);
                    }
                    else
                    {
                        this.flags.Clear(0x10);
                    }
                    this.flags.Set(0x20);
                }
            }
        }
        
        internal void LoadViewStateRecursive(object savedState)
        {
            if ((savedState != null) && !this.flags[4])
            {
                if ((this.Page != null) && this.Page.IsPostBack)
                {
                    object first = null;
                    object state = null;
                    ArrayList childState = null;
                    Pair pair = savedState as Pair;
                    if (pair != null)
                    {
                        first = pair.First;
                        childState = (ArrayList) pair.Second;
                    }
                    else
                    {
                        Triplet triplet = (Triplet) savedState;
                        first = triplet.First;
                        state = triplet.Second;
                        childState = (ArrayList) triplet.Third;
                    }
                    try
                    {
                        if ((state != null) && (this._adapter != null))
                        {
                            this._adapter.LoadAdapterViewState(state);
                        }
                        if (first != null)
                        {
                            this.LoadViewState(first);
                        }
                        if (childState != null)
                        {
                            if (this.LoadViewStateByID)
                            {
                                this.LoadChildViewStateByID(childState);
                            }
                            else
                            {
                                this.LoadChildViewStateByIndex(childState);
                            }
                        }
                    }
                    catch (InvalidCastException)
                    {
                        throw new HttpException(System.Web.SR.GetString("Controls_Cant_Change_Between_Posts"));
                    }
                    catch (IndexOutOfRangeException)
                    {
                        throw new HttpException(System.Web.SR.GetString("Controls_Cant_Change_Between_Posts"));
                    }
                }
                this._controlState = System.Web.UI.ControlState.ViewStateLoaded;
            }
        }
        
        protected internal string MapPathSecure(string virtualPath)
        {
            string str;
            VirtualPath path;
            if (string.IsNullOrEmpty(virtualPath))
            {
                throw new ArgumentNullException("virtualPath", System.Web.SR.GetString("VirtualPath_Length_Zero"));
            }
            this.ResolvePhysicalOrVirtualPath(virtualPath, out path, out str);
            if (str == null)
            {
                str = path.MapPathInternal(this.TemplateControlVirtualDirectory, true);
            }
            HttpRuntime.CheckFilePermission(str);
            return str;
        }
        
        protected virtual bool OnBubbleEvent(object source, EventArgs args)
        {
            return false;
        }
        
        protected virtual void OnDataBinding(EventArgs e)
        {
            if (this.HasEvents())
            {
                EventHandler handler = this._occasionalFields.Events[EventDataBinding] as EventHandler;
                if (handler != null)
                {
                    handler(this, e);
                }
            }
        }
        
        protected internal virtual void OnInit(EventArgs e)
        {
            if (this.HasEvents())
            {
                EventHandler handler = this._occasionalFields.Events[EventInit] as EventHandler;
                if (handler != null)
                {
                    handler(this, e);
                }
            }
        }
        
        protected internal virtual void OnLoad(EventArgs e)
        {
            if (this.HasEvents())
            {
                EventHandler handler = this._occasionalFields.Events[EventLoad] as EventHandler;
                if (handler != null)
                {
                    handler(this, e);
                }
            }
        }
        
        protected internal virtual void OnPreRender(EventArgs e)
        {
            if (this.HasEvents())
            {
                EventHandler handler = this._occasionalFields.Events[EventPreRender] as EventHandler;
                if (handler != null)
                {
                    handler(this, e);
                }
            }
        }
        
        protected internal virtual void OnUnload(EventArgs e)
        {
            if (this.HasEvents())
            {
                EventHandler handler = this._occasionalFields.Events[EventUnload] as EventHandler;
                if (handler != null)
                {
                    handler(this, e);
                }
            }
        }
        
        protected internal Stream OpenFile(string path)
        {
            string physicalPath = null;
            VirtualFile file = null;
            path = path.Trim();
            if (UrlPath.IsAbsolutePhysicalPath(path))
            {
                physicalPath = path;
            }
            else
            {
                file = HostingEnvironment.VirtualPathProvider.GetFile(path);
                MapPathBasedVirtualFile file2 = file as MapPathBasedVirtualFile;
                if (file2 != null)
                {
                    physicalPath = file2.PhysicalPath;
                }
            }
            if (physicalPath != null)
            {
                HttpRuntime.CheckFilePermission(physicalPath);
            }
            if (file != null)
            {
                return file.Open();
            }
            return new FileStream(physicalPath, FileMode.Open, FileAccess.Read, FileShare.Read);
        }
        
        internal Stream OpenFileAndGetDependency(VirtualPath virtualPath, string physicalPath, out CacheDependency dependency)
        {
            Stream stream;
            if ((physicalPath == null) && HostingEnvironment.UsingMapPathBasedVirtualPathProvider)
            {
                physicalPath = virtualPath.MapPathInternal(this.TemplateControlVirtualDirectory, true);
            }
            if (physicalPath != null)
            {
                HttpRuntime.CheckFilePermission(physicalPath);
                stream = new FileStream(physicalPath, FileMode.Open, FileAccess.Read, FileShare.Read);
                dependency = new CacheDependency(0, physicalPath);
                return stream;
            }
            stream = virtualPath.OpenFile();
            dependency = VirtualPathProvider.GetCacheDependency(virtualPath);
            return stream;
        }
        
        internal virtual void PreRenderRecursiveInternal()
        {
            if (!this.Visible)
            {
                this.flags.Set(0x10);
            }
            else
            {
                this.flags.Clear(0x10);
                this.EnsureChildControls();
                if (this._adapter != null)
                {
                    this._adapter.OnPreRender(EventArgs.Empty);
                }
                else
                {
                    this.OnPreRender(EventArgs.Empty);
                }
                if ((this._occasionalFields != null) && (this._occasionalFields.Controls != null))
                {
                    string errorMsg = this._occasionalFields.Controls.SetCollectionReadOnly("Parent_collections_readonly");
                    int count = this._occasionalFields.Controls.Count;
                    for (int i = 0; i < count; i++)
                    {
                        this._occasionalFields.Controls[i].PreRenderRecursiveInternal();
                    }
                    this._occasionalFields.Controls.SetCollectionReadOnly(errorMsg);
                }
            }
            this._controlState = System.Web.UI.ControlState.PreRendered;
        }
        
        internal void PreventAutoID()
        {
            if (!this.flags[0x80])
            {
                this.flags.Set(0x40);
            }
        }
        
        protected void RaiseBubbleEvent(object source, EventArgs args)
        {
            for (Control control = this.Parent; control != null; control = control.Parent)
            {
                if (control.OnBubbleEvent(source, args))
                {
                    return;
                }
            }
        }
        
        protected internal virtual void RemovedControl(Control control)
        {
            if (control.OwnerControl != null)
            {
                throw new InvalidOperationException(System.Web.SR.GetString("Substitution_NotAllowed"));
            }
            if ((this._namingContainer != null) && (control._id != null))
            {
                this._namingContainer.DirtyNameTable();
            }
            control.UnloadRecursive(false);
            control._parent = null;
            control._page = null;
            control._namingContainer = null;
            if (!(control is System.Web.UI.TemplateControl))
            {
                control._templateSourceVirtualDirectory = null;
            }
            control._templateControl = null;
            control.flags.Clear(0x800);
            control.ClearCachedUniqueIDRecursive();
        }
        
        protected internal virtual void Render(HtmlTextWriter writer)
        {
            this.RenderChildren(writer);
        }
        
        protected internal virtual void RenderChildren(HtmlTextWriter writer)
        {
            ICollection children = (this._occasionalFields == null) ? null : this._occasionalFields.Controls;
            this.RenderChildrenInternal(writer, children);
        }
        
        internal void RenderChildrenInternal(HtmlTextWriter writer, ICollection children)
        {
            if ((this.RareFields != null) && (this.RareFields.RenderMethod != null))
            {
                writer.BeginRender();
                this.RareFields.RenderMethod(writer, this);
                writer.EndRender();
            }
            else if (children != null)
            {
                foreach (Control control in children)
                {
                    control.RenderControl(writer);
                }
            }
        }
        
        public virtual void RenderControl(HtmlTextWriter writer)
        {
            this.RenderControl(writer, this.Adapter);
        }
        
        protected void RenderControl(HtmlTextWriter writer, ControlAdapter adapter)
        {
            if (!this.flags[0x10] && !this.flags[0x200])
            {
                HttpContext context = (this.Page == null) ? null : this.Page._context;
                if ((context != null) && context.TraceIsEnabled)
                {
                    int bufferedLength = context.Response.GetBufferedLength();
                    this.RenderControlInternal(writer, adapter);
                    int num2 = context.Response.GetBufferedLength();
                    context.Trace.AddControlSize(this.UniqueID, num2 - bufferedLength);
                }
                else
                {
                    this.RenderControlInternal(writer, adapter);
                }
            }
        }
        
        private void RenderControlInternal(HtmlTextWriter writer, ControlAdapter adapter)
        {
            if (adapter != null)
            {
                adapter.BeginRender(writer);
                adapter.Render(writer);
                adapter.EndRender(writer);
            }
            else
            {
                this.Render(writer);
            }
        }
        
        private void ResetVisible()
        {
            this.Visible = true;
        }
        
        protected virtual ControlAdapter ResolveAdapter()
        {
            if (!this.flags[0x8000])
            {
                if (this.DesignMode)
                {
                    this.flags.Set(0x8000);
                    return null;
                }
                HttpContext context = this.Context;
                if (context != null)
                {
                    this._adapter = context.Request.Browser.GetAdapter(this);
                }
                this.flags.Set(0x8000);
            }
            return this._adapter;
        }
        
        public string ResolveClientUrl(string relativeUrl)
        {
            if ((this.DesignMode && (this.Page != null)) && (this.Page.Site != null))
            {
                IUrlResolutionService service = (IUrlResolutionService) this.Page.Site.GetService(typeof(IUrlResolutionService));
                if (service != null)
                {
                    return service.ResolveClientUrl(relativeUrl);
                }
            }
            if (relativeUrl == null)
            {
                throw new ArgumentNullException("relativeUrl");
            }
            string virtualPathString = VirtualPath.GetVirtualPathString(this.TemplateControlVirtualDirectory);
            if (string.IsNullOrEmpty(virtualPathString))
            {
                return relativeUrl;
            }
            string str2 = this.Context.Request.ClientBaseDir.VirtualPathString;
            if (!UrlPath.IsAppRelativePath(relativeUrl))
            {
                if (StringUtil.EqualsIgnoreCase(str2, virtualPathString))
                {
                    return relativeUrl;
                }
                if ((relativeUrl.Length == 0) || !UrlPath.IsRelativeUrl(relativeUrl))
                {
                    return relativeUrl;
                }
            }
            string to = UrlPath.Combine(virtualPathString, relativeUrl);
            return HttpUtility.UrlPathEncode(UrlPath.MakeRelative(UrlPath.AppendSlashToPathIfNeeded(str2), to));
        }
        
        internal void ResolvePhysicalOrVirtualPath(string path, out VirtualPath virtualPath, out string physicalPath)
        {
            if (UrlPath.IsAbsolutePhysicalPath(path))
            {
                physicalPath = path;
                virtualPath = null;
            }
            else
            {
                physicalPath = null;
                virtualPath = this.TemplateControlVirtualDirectory.Combine(VirtualPath.Create(path));
            }
        }
        
        public string ResolveUrl(string relativeUrl)
        {
            if (relativeUrl == null)
            {
                throw new ArgumentNullException("relativeUrl");
            }
            if ((relativeUrl.Length == 0) || !UrlPath.IsRelativeUrl(relativeUrl))
            {
                return relativeUrl;
            }
            string appRelativeTemplateSourceDirectory = this.AppRelativeTemplateSourceDirectory;
            if (string.IsNullOrEmpty(appRelativeTemplateSourceDirectory))
            {
                return relativeUrl;
            }
            string virtualPath = UrlPath.Combine(appRelativeTemplateSourceDirectory, relativeUrl);
            return this.Context.Response.ApplyAppPathModifier(virtualPath);
        }
        
        protected internal virtual object SaveControlState()
        {
            return null;
        }
        
        internal object SaveControlStateInternal()
        {
            object x = this.SaveControlState();
            object y = null;
            if (this._adapter != null)
            {
                y = this._adapter.SaveAdapterControlState();
            }
            if ((x == null) && (y == null))
            {
                return null;
            }
            return new Pair(x, y);
        }
        
        protected virtual object SaveViewState()
        {
            if (this.flags[0x20])
            {
                this.ViewState["Visible"] = !this.flags[0x10];
            }
            if (this._viewState != null)
            {
                return this._viewState.SaveViewState();
            }
            return null;
        }
        
        internal object SaveViewStateRecursive()
        {
            if (!this.flags[4])
            {
                object y = null;
                if (this._adapter != null)
                {
                    y = this._adapter.SaveAdapterViewState();
                }
                object x = this.SaveViewState();
                ArrayList z = null;
                if (this.HasControls())
                {
                    ControlCollection controls = this._occasionalFields.Controls;
                    int count = controls.Count;
                    bool loadViewStateByID = this.LoadViewStateByID;
                    for (int i = 0; i < count; i++)
                    {
                        Control control = controls[i];
                        object obj4 = control.SaveViewStateRecursive();
                        if (obj4 != null)
                        {
                            if (z == null)
                            {
                                z = new ArrayList(count);
                            }
                            if (loadViewStateByID)
                            {
                                control.EnsureID();
                                z.Add(control.ID);
                            }
                            else
                            {
                                z.Add(i);
                            }
                            z.Add(obj4);
                        }
                    }
                }
                if (this._adapter != null)
                {
                    if (((x != null) || (y != null)) || (z != null))
                    {
                        return new Triplet(x, y, z);
                    }
                }
                else if ((x != null) || (z != null))
                {
                    return new Pair(x, z);
                }
            }
            return null;
        }
        
        internal void SetControlBuilder(ControlBuilder controlBuilder)
        {
            this.RareFieldsEnsured.ControlBuilder = controlBuilder;
        }
        
        internal void SetDesignMode()
        {
            this.flags.Set(0x10000);
            this.flags.Set(0x20000);
        }
        
        protected virtual void SetDesignModeState(IDictionary data)
        {
        }
        
        internal void SetEnableViewStateInternal(bool value)
        {
            if (!value)
            {
                this.flags.Set(4);
            }
            else
            {
                this.flags.Clear(4);
            }
        }
        
        [EditorBrowsable(EditorBrowsableState.Advanced)]
        public void SetRenderMethodDelegate(RenderMethod renderMethod)
        {
            this.RareFieldsEnsured.RenderMethod = renderMethod;
            this.Controls.SetCollectionReadOnly("Collection_readonly_Codeblocks");
        }
        
        internal bool ShouldSerializeEnableTheming()
        {
            return this.flags[0x2000];
        }
        
        private bool ShouldSerializeVisible()
        {
            return this.flags[0x10];
        }
        
        IDictionary IControlDesignerAccessor.GetDesignModeState()
        {
            return this.GetDesignModeState();
        }
        
        void IControlDesignerAccessor.SetDesignModeState(IDictionary data)
        {
            this.SetDesignModeState(data);
        }
        
        void IControlDesignerAccessor.SetOwnerControl(Control owner)
        {
            if (owner == this)
            {
                throw new ArgumentException(System.Web.SR.GetString("Control_CannotOwnSelf"), "owner");
            }
            this.OwnerControl = owner;
            this._parent = owner.Parent;
            this._page = owner.Page;
        }
        
        void IParserAccessor.AddParsedSubObject(object obj)
        {
            this.AddParsedSubObject(obj);
        }
        
        protected virtual void TrackViewState()
        {
            if (this._viewState != null)
            {
                this._viewState.TrackViewState();
            }
            this.flags.Set(2);
        }
        
        internal virtual void UnloadRecursive(bool dispose)
        {
            System.Web.UI.Page page = this.Page;
            if ((page != null) && page.RequiresControlState(this))
            {
                page.UnregisterRequiresControlState(this);
                this.RareFieldsEnsured.RequiredControlState = true;
            }
            if (this.flags[0x200000])
            {
                this._id = null;
                this.flags.Clear(0x200000);
            }
            if ((this._occasionalFields != null) && (this._occasionalFields.Controls != null))
            {
                string errorMsg = this._occasionalFields.Controls.SetCollectionReadOnly("Parent_collections_readonly");
                int count = this._occasionalFields.Controls.Count;
                for (int i = 0; i < count; i++)
                {
                    this._occasionalFields.Controls[i].UnloadRecursive(dispose);
                }
                this._occasionalFields.Controls.SetCollectionReadOnly(errorMsg);
            }
            if (this._adapter != null)
            {
                this._adapter.OnUnload(EventArgs.Empty);
            }
            else
            {
                this.OnUnload(EventArgs.Empty);
            }
            if (dispose)
            {
                this.Dispose();
            }
            if (this.IsReloadable)
            {
                this._controlState = System.Web.UI.ControlState.Constructed;
            }
        }
        
        private void UpdateNamingContainer(Control namingContainer)
        {
            if ((this._namingContainer != null) && (this._namingContainer != namingContainer))
            {
                this.ClearCachedUniqueIDRecursive();
            }
            this._namingContainer = namingContainer;
        }
        
        internal void ValidateEvent(string uniqueID)
        {
            this.ValidateEvent(uniqueID, string.Empty);
        }
        
        internal void ValidateEvent(string uniqueID, string eventArgument)
        {
            if ((this.Page != null) && this.SupportsEventValidation)
            {
                this.Page.ClientScript.ValidateEvent(uniqueID, eventArgument);
            }
        }
        
        protected ControlAdapter Adapter
        {
            get
            {
                if (!this.flags[0x8000])
                {
                    this._adapter = this.ResolveAdapter();
                    this.flags.Set(0x8000);
                }
                return this._adapter;
            }
        }
        
        [EditorBrowsable(EditorBrowsableState.Advanced), DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden), Browsable(false), WebSysDescription("Control_TemplateSourceDirectory")]
        public string AppRelativeTemplateSourceDirectory
        {
            get
            {
                return VirtualPath.GetAppRelativeVirtualPathStringOrEmpty(this.TemplateControlVirtualDirectory);
            }
            [EditorBrowsable(EditorBrowsableState.Never)]
            set
            {
                this.TemplateControlVirtualDirectory = VirtualPath.CreateNonRelativeAllowNull(value);
            }
        }
        
        [Browsable(false), EditorBrowsable(EditorBrowsableState.Never), Bindable(false), DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
        public Control BindingContainer
        {
            get
            {
                Control namingContainer = this.NamingContainer;
                while (namingContainer is INonBindingContainer)
                {
                    namingContainer = namingContainer.BindingContainer;
                }
                return namingContainer;
            }
        }
        
        protected bool ChildControlsCreated
        {
            get
            {
                return this.flags[8];
            }
            set
            {
                if (!value && this.flags[8])
                {
                    this.Controls.Clear();
                }
                if (value)
                {
                    this.flags.Set(8);
                }
                else
                {
                    this.flags.Clear(8);
                }
            }
        }
        
        [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden), Browsable(false), WebSysDescription("Control_ClientID")]
        public virtual string ClientID
        {
            get
            {
                this.EnsureID();
                string uniqueID = this.UniqueID;
                if ((uniqueID != null) && (uniqueID.IndexOf(this.IdSeparator) >= 0))
                {
                    return uniqueID.Replace(this.IdSeparator, '_');
                }
                return uniqueID;
            }
        }
        
        protected char ClientIDSeparator
        {
            get
            {
                return '_';
            }
        }
        
        [Browsable(false), DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
        protected internal virtual HttpContext Context
        {
            get
            {
                System.Web.UI.Page page = this.Page;
                if (page != null)
                {
                    return page.Context;
                }
                return HttpContext.Current;
            }
        }
        
        [Browsable(false), DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden), WebSysDescription("Control_Controls")]
        public virtual ControlCollection Controls
        {
            get
            {
                if ((this._occasionalFields == null) || (this._occasionalFields.Controls == null))
                {
                    this.EnsureOccasionalFields();
                    this._occasionalFields.Controls = this.CreateControlCollection();
                }
                return this._occasionalFields.Controls;
            }
        }
        
        internal System.Web.UI.ControlState ControlState
        {
            get
            {
                return this._controlState;
            }
            set
            {
                this._controlState = value;
            }
        }
        
        protected internal bool DesignMode
        {
            get
            {
                if (!this.flags[0x20000])
                {
                    System.Web.UI.Page page = this.Page;
                    if (page != null)
                    {
                        if (page.GetDesignModeInternal())
                        {
                            this.flags.Set(0x10000);
                        }
                        else
                        {
                            this.flags.Clear(0x10000);
                        }
                    }
                    else if (this.Site != null)
                    {
                        if (this.Site.DesignMode)
                        {
                            this.flags.Set(0x10000);
                        }
                        else
                        {
                            this.flags.Clear(0x10000);
                        }
                    }
                    else if ((this.Parent != null) && this.Parent.DesignMode)
                    {
                        this.flags.Set(0x10000);
                    }
                    this.flags.Set(0x20000);
                }
                return this.flags[0x10000];
            }
        }
        
        internal bool EnableLegacyRendering
        {
            get
            {
                System.Web.UI.Page page = this.Page;
                if (page != null)
                {
                    return (page.XhtmlConformanceMode == XhtmlConformanceMode.Legacy);
                }
                return ((!this.DesignMode && (this.Adapter == null)) && (this.GetXhtmlConformanceSection().Mode == XhtmlConformanceMode.Legacy));
            }
        }
        
        [WebCategory("Behavior"), Browsable(false), DefaultValue(true), Themeable(false), WebSysDescription("Control_EnableTheming")]
        public virtual bool EnableTheming
        {
            get
            {
                if (!this.flags[0x2000] && (this.Parent != null))
                {
                    return this.Parent.EnableTheming;
                }
                return !this.flags[0x1000];
            }
            set
            {
                if ((this._controlState >= System.Web.UI.ControlState.FrameworkInitialized) && !this.DesignMode)
                {
                    throw new InvalidOperationException(System.Web.SR.GetString("PropertySetBeforePreInitOrAddToControls", new object[] { "EnableTheming" }));
                }
                if (!value)
                {
                    this.flags.Set(0x1000);
                }
                else
                {
                    this.flags.Clear(0x1000);
                }
                this.flags.Set(0x2000);
            }
        }
        
        [WebSysDescription("Control_MaintainState"), DefaultValue(true), Themeable(false), WebCategory("Behavior")]
        public virtual bool EnableViewState
        {
            get
            {
                return !this.flags[4];
            }
            set
            {
                this.SetEnableViewStateInternal(value);
            }
        }
        
        protected EventHandlerList Events
        {
            get
            {
                this.EnsureOccasionalFields();
                if (this._occasionalFields.Events == null)
                {
                    this._occasionalFields.Events = new EventHandlerList();
                }
                return this._occasionalFields.Events;
            }
        }
        
        protected bool HasChildViewState
        {
            get
            {
                return (((this._occasionalFields != null) && (this._occasionalFields.ControlsViewState != null)) && (this._occasionalFields.ControlsViewState.Count > 0));
            }
        }
        
        [Filterable(false), WebSysDescription("Control_ID"), ParenthesizePropertyName(true), MergableProperty(false), Themeable(false)]
        public virtual string ID
        {
            get
            {
                if (!this.flags[1] && !this.flags[0x800])
                {
                    return null;
                }
                return this._id;
            }
            set
            {
                if ((value != null) && (value.Length == 0))
                {
                    value = null;
                }
                string str = this._id;
                this._id = value;
                this.ClearCachedUniqueIDRecursive();
                this.flags.Set(1);
                this.flags.Clear(0x200000);
                if ((this._namingContainer != null) && (str != null))
                {
                    this._namingContainer.DirtyNameTable();
                }
            }
        }
        
        protected char IdSeparator
        {
            get
            {
                if (this.Page != null)
                {
                    return this.Page.IdSeparator;
                }
                return this.IdSeparatorFromConfig;
            }
        }
        
        internal char IdSeparatorFromConfig
        {
            get
            {
                if (!this.EnableLegacyRendering)
                {
                    return '$';
                }
                return ':';
            }
        }
        
        internal bool IsBindingContainer
        {
            get
            {
                return ((this is INamingContainer) && !(this is INonBindingContainer));
            }
        }
        
        protected internal bool IsChildControlStateCleared
        {
            get
            {
                return this.flags[0x40000];
            }
        }
        
        internal bool IsParentedToUpdatePanel
        {
            get
            {
                for (Control control = this.Parent; control != null; control = control.Parent)
                {
                    if (control is IUpdatePanel)
                    {
                        return true;
                    }
                }
                return false;
            }
        }
        
        internal virtual bool IsReloadable
        {
            get
            {
                return false;
            }
        }
        
        protected bool IsTrackingViewState
        {
            get
            {
                return this.flags[2];
            }
        }
        
        protected internal bool IsViewStateEnabled
        {
            get
            {
                for (Control control = this; control != null; control = control.Parent)
                {
                    if (!control.EnableViewState)
                    {
                        return false;
                    }
                }
                return true;
            }
        }
        
        protected bool LoadViewStateByID
        {
            get
            {
                return ViewStateModeByIdAttribute.IsEnabled(base.GetType());
            }
        }
        
        [WebSysDescription("Control_NamingContainer"), Bindable(false), Browsable(false), DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
        public virtual Control NamingContainer
        {
            get
            {
                if ((this._namingContainer == null) && (this.Parent != null))
                {
                    if (this.Parent.flags[0x80])
                    {
                        this._namingContainer = this.Parent;
                    }
                    else
                    {
                        this._namingContainer = this.Parent.NamingContainer;
                    }
                }
                return this._namingContainer;
            }
        }
        
        private Control OwnerControl
        {
            get
            {
                if (this.RareFields == null)
                {
                    return null;
                }
                return this.RareFields.OwnerControl;
            }
            set
            {
                this.RareFieldsEnsured.OwnerControl = value;
            }
        }
        
        [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden), Browsable(false), WebSysDescription("Control_Page"), Bindable(false)]
        public virtual System.Web.UI.Page Page
        {
            get
            {
                if ((this._page == null) && (this.Parent != null))
                {
                    this._page = this.Parent.Page;
                }
                return this._page;
            }
            set
            {
                if (this.OwnerControl != null)
                {
                    throw new InvalidOperationException();
                }
                this._page = value;
            }
        }
        
        [Bindable(false), WebSysDescription("Control_Parent"), DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden), Browsable(false)]
        public virtual Control Parent
        {
            get
            {
                return this._parent;
            }
        }
        
        internal IPostBackDataHandler PostBackDataHandler
        {
            get
            {
                IPostBackDataHandler handler = this._adapter as IPostBackDataHandler;
                if (handler != null)
                {
                    return handler;
                }
                return (this as IPostBackDataHandler);
            }
        }
        
        internal IPostBackEventHandler PostBackEventHandler
        {
            get
            {
                IPostBackEventHandler handler = this._adapter as IPostBackEventHandler;
                if (handler != null)
                {
                    return handler;
                }
                return (this as IPostBackEventHandler);
            }
        }
        
        private ControlRareFields RareFields
        {
            get
            {
                if (this._occasionalFields != null)
                {
                    return this._occasionalFields.RareFields;
                }
                return null;
            }
        }
        
        private ControlRareFields RareFieldsEnsured
        {
            get
            {
                this.EnsureOccasionalFields();
                ControlRareFields rareFields = this._occasionalFields.RareFields;
                if (rareFields == null)
                {
                    rareFields = new ControlRareFields();
                    this._occasionalFields.RareFields = rareFields;
                }
                return rareFields;
            }
        }
        
        [WebSysDescription("Control_Site"), EditorBrowsable(EditorBrowsableState.Advanced), DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden), Browsable(false)]
        public ISite Site
        {
            get
            {
                if (this.OwnerControl != null)
                {
                    return this.OwnerControl.Site;
                }
                if (this.RareFields != null)
                {
                    return this.RareFields.Site;
                }
                return null;
            }
            set
            {
                if (this.OwnerControl != null)
                {
                    throw new InvalidOperationException(System.Web.SR.GetString("Substitution_SiteNotAllowed"));
                }
                this.RareFieldsEnsured.Site = value;
                this.flags.Clear(0x20000);
            }
        }
        
        [DefaultValue(""), Browsable(false), WebSysDescription("Control_SkinId"), Filterable(false), WebCategory("Behavior")]
        public virtual string SkinID
        {
            get
            {
                if ((this._occasionalFields != null) && (this._occasionalFields.SkinId != null))
                {
                    return this._occasionalFields.SkinId;
                }
                return string.Empty;
            }
            set
            {
                if (!this.DesignMode)
                {
                    if (this.flags[0x4000])
                    {
                        throw new InvalidOperationException(System.Web.SR.GetString("PropertySetBeforeStyleSheetApplied", new object[] { "SkinId" }));
                    }
                    if (this._controlState >= System.Web.UI.ControlState.FrameworkInitialized)
                    {
                        throw new InvalidOperationException(System.Web.SR.GetString("PropertySetBeforePreInitOrAddToControls", new object[] { "SkinId" }));
                    }
                }
                this.EnsureOccasionalFields();
                this._occasionalFields.SkinId = value;
            }
        }
        
        internal string SpacerImageUrl
        {
            get
            {
                this.EnsureOccasionalFields();
                if (this._occasionalFields.SpacerImageUrl == null)
                {
                    this._occasionalFields.SpacerImageUrl = this.Page.ClientScript.GetWebResourceUrl(typeof(WebControl), "Spacer.gif");
                }
                return this._occasionalFields.SpacerImageUrl;
            }
        }
        
        private bool SupportsEventValidation
        {
            get
            {
                return SupportsEventValidationAttribute.SupportsEventValidation(base.GetType());
            }
        }
        
        [Browsable(false), DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
        ControlBuilder IControlBuilderAccessor.ControlBuilder
        {
            get
            {
                if (this.RareFields == null)
                {
                    return null;
                }
                return this.RareFields.ControlBuilder;
            }
        }
        
        IDictionary IControlDesignerAccessor.UserData
        {
            get
            {
                ControlRareFields rareFieldsEnsured = this.RareFieldsEnsured;
                if (rareFieldsEnsured.ControlDesignerAccessorUserData == null)
                {
                    rareFieldsEnsured.ControlDesignerAccessorUserData = new HybridDictionary();
                }
                return rareFieldsEnsured.ControlDesignerAccessorUserData;
            }
        }
        
        DataBindingCollection IDataBindingsAccessor.DataBindings
        {
            get
            {
                ControlRareFields rareFieldsEnsured = this.RareFieldsEnsured;
                if (rareFieldsEnsured.DataBindings == null)
                {
                    rareFieldsEnsured.DataBindings = new DataBindingCollection();
                }
                return rareFieldsEnsured.DataBindings;
            }
        }
        
        bool IDataBindingsAccessor.HasDataBindings
        {
            get
            {
                return (((this.RareFields != null) && (this.RareFields.DataBindings != null)) && (this.RareFields.DataBindings.Count != 0));
            }
        }
        
        ExpressionBindingCollection IExpressionsAccessor.Expressions
        {
            get
            {
                ExpressionBindingCollection expressionBindings = this.RareFieldsEnsured.ExpressionBindings;
                if (expressionBindings == null)
                {
                    expressionBindings = new ExpressionBindingCollection();
                    this.RareFields.ExpressionBindings = expressionBindings;
                }
                return expressionBindings;
            }
        }
        
        bool IExpressionsAccessor.HasExpressions
        {
            get
            {
                if (this.RareFields == null)
                {
                    return false;
                }
                ExpressionBindingCollection expressionBindings = this.RareFields.ExpressionBindings;
                return ((expressionBindings != null) && (expressionBindings.Count > 0));
            }
        }
        
        [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden), WebSysDescription("Control_TemplateControl"), Bindable(false), Browsable(false)]
        public System.Web.UI.TemplateControl TemplateControl
        {
            get
            {
                return this.GetTemplateControl();
            }
            [EditorBrowsable(EditorBrowsableState.Never)]
            set
            {
                this._templateControl = value;
            }
        }
        
        internal VirtualPath TemplateControlVirtualDirectory
        {
            get
            {
                if (this._templateSourceVirtualDirectory == null)
                {
                    System.Web.UI.TemplateControl templateControl = this.TemplateControl;
                    if (templateControl == null)
                    {
                        HttpContext context = this.Context;
                        if (context != null)
                        {
                            this._templateSourceVirtualDirectory = context.Request.CurrentExecutionFilePathObject.Parent;
                        }
                        return this._templateSourceVirtualDirectory;
                    }
                    if (templateControl != this)
                    {
                        this._templateSourceVirtualDirectory = templateControl.TemplateControlVirtualDirectory;
                    }
                }
                return this._templateSourceVirtualDirectory;
            }
            set
            {
                this._templateSourceVirtualDirectory = value;
            }
        }
        
        [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden), WebSysDescription("Control_TemplateSourceDirectory"), Browsable(false)]
        public virtual string TemplateSourceDirectory
        {
            get
            {
                if (this.TemplateControlVirtualDirectory == null)
                {
                    return string.Empty;
                }
                return this.TemplateControlVirtualDirectory.VirtualPathStringNoTrailingSlash;
            }
        }
        
        [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden), Browsable(false), WebSysDescription("Control_UniqueID")]
        public virtual string UniqueID
        {
            get
            {
                if (this._cachedUniqueID == null)
                {
                    Control namingContainer = this.NamingContainer;
                    if (namingContainer == null)
                    {
                        return this._id;
                    }
                    if (this._id == null)
                    {
                        this.GenerateAutomaticID();
                    }
                    if (this.Page == namingContainer)
                    {
                        this._cachedUniqueID = this._id;
                    }
                    else
                    {
                        string uniqueIDPrefix = namingContainer.GetUniqueIDPrefix();
                        if (uniqueIDPrefix.Length == 0)
                        {
                            return this._id;
                        }
                        this._cachedUniqueID = uniqueIDPrefix + this._id;
                    }
                }
                return this._cachedUniqueID;
            }
        }
        
        [Browsable(false), DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden), WebSysDescription("Control_State")]
        protected virtual StateBag ViewState
        {
            get
            {
                if (this._viewState == null)
                {
                    this._viewState = new StateBag(this.ViewStateIgnoresCase);
                    if (this.IsTrackingViewState)
                    {
                        this._viewState.TrackViewState();
                    }
                }
                return this._viewState;
            }
        }
        
        [Browsable(false), DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
        protected virtual bool ViewStateIgnoresCase
        {
            get
            {
                return false;
            }
        }
        
        [DefaultValue(true), Bindable(true), WebCategory("Behavior"), WebSysDescription("Control_Visible")]
        public virtual bool Visible
        {
            get
            {
                if (this.flags[0x10])
                {
                    return false;
                }
                if ((this._parent != null) && !this.DesignMode)
                {
                    return this._parent.Visible;
                }
                return true;
            }
            set
            {
                if (this.flags[2])
                {
                    bool flag = !this.flags[0x10];
                    if (flag != value)
                    {
                        this.flags.Set(0x20);
                    }
                }
                if (!value)
                {
                    this.flags.Set(0x10);
                }
                else
                {
                    this.flags.Clear(0x10);
                }
            }
        }
        
        private sealed class ControlRareFields : IDisposable
        {
            public System.Web.UI.ControlBuilder ControlBuilder;
            public IDictionary ControlDesignerAccessorUserData;
            public DataBindingCollection DataBindings;
            public IDictionary DesignModeState;
            public ExpressionBindingCollection ExpressionBindings;
            public Control OwnerControl;
            public System.Web.UI.RenderMethod RenderMethod;
            public bool RequiredControlState;
            public ISite Site;
            
            internal ControlRareFields()
            {
            }
            
            public void Dispose()
            {
                this.ControlBuilder = null;
                if (this.OwnerControl != null)
                {
                    this.OwnerControl.Dispose();
                }
                this.ControlDesignerAccessorUserData = null;
                this.DesignModeState = null;
            }
        }
        
        private sealed class OccasionalFields : IDisposable
        {
            public ControlCollection Controls;
            public IDictionary ControlsViewState;
            public EventHandlerList Events;
            public IDictionary NamedControls;
            public int NamedControlsID;
            public Control.ControlRareFields RareFields;
            public string SkinId;
            public string SpacerImageUrl;
            public string UniqueIDPrefix;
            
            internal OccasionalFields()
            {
            }
            
            public void Dispose()
            {
                if (this.Events != null)
                {
                    this.Events.Dispose();
                    this.Events = null;
                }
                if (this.RareFields != null)
                {
                    this.RareFields.Dispose();
                }
                this.ControlsViewState = null;
            }
        }
    }
}

这就是repeater的源码,你自己看看。

顾晓北 | 园豆:10898 (专家六级) | 2013-03-27 15:55

@枼秋: 不好意思,贴错了。下面才是repeater的源码。

 

View Code
// Generated by .NET Reflector from C:\Windows\assembly\GAC_32\System.Web\2.0.0.0__b03f5f7f11d50a3a\System.Web.dll
namespace System.Web.UI.WebControls
{
    using System;
    using System.Collections;
    using System.ComponentModel;
    using System.Security.Permissions;
    using System.Web;
    using System.Web.UI;
    
    [DefaultEvent("ItemCommand"), DefaultProperty("DataSource"), ParseChildren(true), PersistChildren(false), Designer("System.Web.UI.Design.WebControls.RepeaterDesigner, System.Design, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"), AspNetHostingPermission(SecurityAction.LinkDemand, Level=AspNetHostingPermissionLevel.Minimal), AspNetHostingPermission(SecurityAction.InheritanceDemand, Level=AspNetHostingPermissionLevel.Minimal)]
    public class Repeater : Control, INamingContainer
    {
        private DataSourceSelectArguments _arguments;
        private DataSourceView _currentView;
        private bool _currentViewIsFromDataSourceID;
        private bool _currentViewValid;
        private bool _inited;
        private bool _pagePreLoadFired;
        private bool _requiresDataBinding;
        private bool _throwOnDataPropertyChange;
        private ITemplate alternatingItemTemplate;
        private object dataSource;
        private static readonly object EventItemCommand = new object();
        private static readonly object EventItemCreated = new object();
        private static readonly object EventItemDataBound = new object();
        private ITemplate footerTemplate;
        private ITemplate headerTemplate;
        internal const string ItemCountViewStateKey = "_!ItemCount";
        private ArrayList itemsArray;
        private RepeaterItemCollection itemsCollection;
        private ITemplate itemTemplate;
        private ITemplate separatorTemplate;
        
        [WebCategory("Action"), WebSysDescription("Repeater_OnItemCommand")]
        public event RepeaterCommandEventHandler ItemCommand
        {
            add
            {
                base.Events.AddHandler(EventItemCommand, value);
            }
            remove
            {
                base.Events.RemoveHandler(EventItemCommand, value);
            }
        }
        
        [WebCategory("Behavior"), WebSysDescription("DataControls_OnItemCreated")]
        public event RepeaterItemEventHandler ItemCreated
        {
            add
            {
                base.Events.AddHandler(EventItemCreated, value);
            }
            remove
            {
                base.Events.RemoveHandler(EventItemCreated, value);
            }
        }
        
        [WebCategory("Behavior"), WebSysDescription("DataControls_OnItemDataBound")]
        public event RepeaterItemEventHandler ItemDataBound
        {
            add
            {
                base.Events.AddHandler(EventItemDataBound, value);
            }
            remove
            {
                base.Events.RemoveHandler(EventItemDataBound, value);
            }
        }
        
        private DataSourceView ConnectToDataSourceView()
        {
            if (!this._currentViewValid || base.DesignMode)
            {
                if ((this._currentView != null) && this._currentViewIsFromDataSourceID)
                {
                    this._currentView.DataSourceViewChanged -= new EventHandler(this.OnDataSourceViewChanged);
                }
                IDataSource source = null;
                string dataSourceID = this.DataSourceID;
                if (dataSourceID.Length != 0)
                {
                    Control control = DataBoundControlHelper.FindControl(this, dataSourceID);
                    if (control == null)
                    {
                        throw new HttpException(System.Web.SR.GetString("DataControl_DataSourceDoesntExist", new object[] { this.ID, dataSourceID }));
                    }
                    source = control as IDataSource;
                    if (source == null)
                    {
                        throw new HttpException(System.Web.SR.GetString("DataControl_DataSourceIDMustBeDataControl", new object[] { this.ID, dataSourceID }));
                    }
                }
                if (source == null)
                {
                    source = new ReadOnlyDataSource(this.DataSource, this.DataMember);
                }
                else if (this.DataSource != null)
                {
                    throw new InvalidOperationException(System.Web.SR.GetString("DataControl_MultipleDataSources", new object[] { this.ID }));
                }
                DataSourceView view = source.GetView(this.DataMember);
                if (view == null)
                {
                    throw new InvalidOperationException(System.Web.SR.GetString("DataControl_ViewNotFound", new object[] { this.ID }));
                }
                this._currentViewIsFromDataSourceID = this.IsBoundUsingDataSourceID;
                this._currentView = view;
                if ((this._currentView != null) && this._currentViewIsFromDataSourceID)
                {
                    this._currentView.DataSourceViewChanged += new EventHandler(this.OnDataSourceViewChanged);
                }
                this._currentViewValid = true;
            }
            return this._currentView;
        }
        
        protected internal override void CreateChildControls()
        {
            this.Controls.Clear();
            if (this.ViewState["_!ItemCount"] != null)
            {
                this.CreateControlHierarchy(false);
            }
            else
            {
                this.itemsArray = new ArrayList();
            }
            base.ClearChildViewState();
        }
        
        protected virtual void CreateControlHierarchy(bool useDataSource)
        {
            IEnumerable data = null;
            int dataItemCount = -1;
            if (this.itemsArray != null)
            {
                this.itemsArray.Clear();
            }
            else
            {
                this.itemsArray = new ArrayList();
            }
            if (!useDataSource)
            {
                dataItemCount = (int) this.ViewState["_!ItemCount"];
                if (dataItemCount != -1)
                {
                    data = new DummyDataSource(dataItemCount);
                    this.itemsArray.Capacity = dataItemCount;
                }
            }
            else
            {
                data = this.GetData();
                ICollection is2 = data as ICollection;
                if (is2 != null)
                {
                    this.itemsArray.Capacity = is2.Count;
                }
            }
            if (data != null)
            {
                int itemIndex = 0;
                bool flag = this.separatorTemplate != null;
                dataItemCount = 0;
                if (this.headerTemplate != null)
                {
                    this.CreateItem(-1, ListItemType.Header, useDataSource, null);
                }
                foreach (object obj2 in data)
                {
                    if (flag && (dataItemCount > 0))
                    {
                        this.CreateItem(itemIndex - 1, ListItemType.Separator, useDataSource, null);
                    }
                    ListItemType itemType = ((itemIndex % 2) == 0) ? ListItemType.Item : ListItemType.AlternatingItem;
                    RepeaterItem item = this.CreateItem(itemIndex, itemType, useDataSource, obj2);
                    this.itemsArray.Add(item);
                    dataItemCount++;
                    itemIndex++;
                }
                if (this.footerTemplate != null)
                {
                    this.CreateItem(-1, ListItemType.Footer, useDataSource, null);
                }
            }
            if (useDataSource)
            {
                this.ViewState["_!ItemCount"] = (data != null) ? dataItemCount : -1;
            }
        }
        
        protected virtual DataSourceSelectArguments CreateDataSourceSelectArguments()
        {
            return DataSourceSelectArguments.Empty;
        }
        
        protected virtual RepeaterItem CreateItem(int itemIndex, ListItemType itemType)
        {
            return new RepeaterItem(itemIndex, itemType);
        }
        
        private RepeaterItem CreateItem(int itemIndex, ListItemType itemType, bool dataBind, object dataItem)
        {
            RepeaterItem item = this.CreateItem(itemIndex, itemType);
            RepeaterItemEventArgs e = new RepeaterItemEventArgs(item);
            this.InitializeItem(item);
            if (dataBind)
            {
                item.DataItem = dataItem;
            }
            this.OnItemCreated(e);
            this.Controls.Add(item);
            if (dataBind)
            {
                item.DataBind();
                this.OnItemDataBound(e);
                item.DataItem = null;
            }
            return item;
        }
        
        public override void DataBind()
        {
            if ((!this.IsBoundUsingDataSourceID || !base.DesignMode) || (base.Site != null))
            {
                this.RequiresDataBinding = false;
                this.OnDataBinding(EventArgs.Empty);
            }
        }
        
        protected void EnsureDataBound()
        {
            try
            {
                this._throwOnDataPropertyChange = true;
                if (this.RequiresDataBinding && (this.DataSourceID.Length > 0))
                {
                    this.DataBind();
                }
            }
            finally
            {
                this._throwOnDataPropertyChange = false;
            }
        }
        
        protected virtual IEnumerable GetData()
        {
            DataSourceView view = this.ConnectToDataSourceView();
            if (view != null)
            {
                return view.ExecuteSelect(this.SelectArguments);
            }
            return null;
        }
        
        protected virtual void InitializeItem(RepeaterItem item)
        {
            ITemplate itemTemplate = null;
            switch (item.ItemType)
            {
                case ListItemType.Header:
                    itemTemplate = this.headerTemplate;
                    goto Label_005B;
                
                case ListItemType.Footer:
                    itemTemplate = this.footerTemplate;
                    goto Label_005B;
                
                case ListItemType.Item:
                    break;
                
                case ListItemType.AlternatingItem:
                    itemTemplate = this.alternatingItemTemplate;
                    if (itemTemplate != null)
                    {
                        goto Label_005B;
                    }
                    break;
                
                case ListItemType.Separator:
                    itemTemplate = this.separatorTemplate;
                    goto Label_005B;
                
                default:
                    goto Label_005B;
            }
            itemTemplate = this.itemTemplate;
        Label_005B:
            if (itemTemplate != null)
            {
                itemTemplate.InstantiateIn(item);
            }
        }
        
        protected override bool OnBubbleEvent(object sender, EventArgs e)
        {
            bool flag = false;
            if (e is RepeaterCommandEventArgs)
            {
                this.OnItemCommand((RepeaterCommandEventArgs) e);
                flag = true;
            }
            return flag;
        }
        
        protected override void OnDataBinding(EventArgs e)
        {
            base.OnDataBinding(e);
            this.Controls.Clear();
            base.ClearChildViewState();
            this.CreateControlHierarchy(true);
            base.ChildControlsCreated = true;
        }
        
        protected virtual void OnDataPropertyChanged()
        {
            if (this._throwOnDataPropertyChange)
            {
                throw new HttpException(System.Web.SR.GetString("DataBoundControl_InvalidDataPropertyChange", new object[] { this.ID }));
            }
            if (this._inited)
            {
                this.RequiresDataBinding = true;
            }
            this._currentViewValid = false;
        }
        
        protected virtual void OnDataSourceViewChanged(object sender, EventArgs e)
        {
            this.RequiresDataBinding = true;
        }
        
        protected internal override void OnInit(EventArgs e)
        {
            base.OnInit(e);
            if (this.Page != null)
            {
                this.Page.PreLoad += new EventHandler(this.OnPagePreLoad);
                if (!base.IsViewStateEnabled && this.Page.IsPostBack)
                {
                    this.RequiresDataBinding = true;
                }
            }
        }
        
        protected virtual void OnItemCommand(RepeaterCommandEventArgs e)
        {
            RepeaterCommandEventHandler handler = (RepeaterCommandEventHandler) base.Events[EventItemCommand];
            if (handler != null)
            {
                handler(this, e);
            }
        }
        
        protected virtual void OnItemCreated(RepeaterItemEventArgs e)
        {
            RepeaterItemEventHandler handler = (RepeaterItemEventHandler) base.Events[EventItemCreated];
            if (handler != null)
            {
                handler(this, e);
            }
        }
        
        protected virtual void OnItemDataBound(RepeaterItemEventArgs e)
        {
            RepeaterItemEventHandler handler = (RepeaterItemEventHandler) base.Events[EventItemDataBound];
            if (handler != null)
            {
                handler(this, e);
            }
        }
        
        protected internal override void OnLoad(EventArgs e)
        {
            this._inited = true;
            this.ConnectToDataSourceView();
            if (((this.Page != null) && !this._pagePreLoadFired) && (this.ViewState["_!ItemCount"] == null))
            {
                if (!this.Page.IsPostBack)
                {
                    this.RequiresDataBinding = true;
                }
                else if (base.IsViewStateEnabled)
                {
                    this.RequiresDataBinding = true;
                }
            }
            base.OnLoad(e);
        }
        
        private void OnPagePreLoad(object sender, EventArgs e)
        {
            this._inited = true;
            if (this.Page != null)
            {
                this.Page.PreLoad -= new EventHandler(this.OnPagePreLoad);
                if (!this.Page.IsPostBack)
                {
                    this.RequiresDataBinding = true;
                }
                if ((this.Page.IsPostBack && base.IsViewStateEnabled) && (this.ViewState["_!ItemCount"] == null))
                {
                    this.RequiresDataBinding = true;
                }
                this._pagePreLoadFired = true;
            }
        }
        
        protected internal override void OnPreRender(EventArgs e)
        {
            this.EnsureDataBound();
            base.OnPreRender(e);
        }
        
        [DefaultValue((string) null), TemplateContainer(typeof(RepeaterItem)), WebSysDescription("Repeater_AlternatingItemTemplate"), PersistenceMode(PersistenceMode.InnerProperty), Browsable(false)]
        public virtual ITemplate AlternatingItemTemplate
        {
            get
            {
                return this.alternatingItemTemplate;
            }
            set
            {
                this.alternatingItemTemplate = value;
            }
        }
        
        public override ControlCollection Controls
        {
            get
            {
                this.EnsureChildControls();
                return base.Controls;
            }
        }
        
        [WebSysDescription("Repeater_DataMember"), DefaultValue(""), WebCategory("Data")]
        public virtual string DataMember
        {
            get
            {
                object obj2 = this.ViewState["DataMember"];
                if (obj2 != null)
                {
                    return (string) obj2;
                }
                return string.Empty;
            }
            set
            {
                this.ViewState["DataMember"] = value;
                this.OnDataPropertyChanged();
            }
        }
        
        [Bindable(true), WebSysDescription("BaseDataBoundControl_DataSource"), WebCategory("Data"), DefaultValue((string) null), DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
        public virtual object DataSource
        {
            get
            {
                return this.dataSource;
            }
            set
            {
                if (((value != null) && !(value is IListSource)) && !(value is IEnumerable))
                {
                    throw new ArgumentException(System.Web.SR.GetString("Invalid_DataSource_Type", new object[] { this.ID }));
                }
                this.dataSource = value;
                this.OnDataPropertyChanged();
            }
        }
        
        [WebSysDescription("BaseDataBoundControl_DataSourceID"), DefaultValue(""), IDReferenceProperty(typeof(DataSourceControl)), WebCategory("Data")]
        public virtual string DataSourceID
        {
            get
            {
                object obj2 = this.ViewState["DataSourceID"];
                if (obj2 != null)
                {
                    return (string) obj2;
                }
                return string.Empty;
            }
            set
            {
                this.ViewState["DataSourceID"] = value;
                this.OnDataPropertyChanged();
            }
        }
        
        [Browsable(true)]
        public override bool EnableTheming
        {
            get
            {
                return base.EnableTheming;
            }
            set
            {
                base.EnableTheming = value;
            }
        }
        
        [Browsable(false), PersistenceMode(PersistenceMode.InnerProperty), TemplateContainer(typeof(RepeaterItem)), WebSysDescription("Repeater_FooterTemplate"), DefaultValue((string) null)]
        public virtual ITemplate FooterTemplate
        {
            get
            {
                return this.footerTemplate;
            }
            set
            {
                this.footerTemplate = value;
            }
        }
        
        [DefaultValue((string) null), PersistenceMode(PersistenceMode.InnerProperty), TemplateContainer(typeof(RepeaterItem)), WebSysDescription("WebControl_HeaderTemplate"), Browsable(false)]
        public virtual ITemplate HeaderTemplate
        {
            get
            {
                return this.headerTemplate;
            }
            set
            {
                this.headerTemplate = value;
            }
        }
        
        protected bool Initialized
        {
            get
            {
                return this._inited;
            }
        }
        
        protected bool IsBoundUsingDataSourceID
        {
            get
            {
                return (this.DataSourceID.Length > 0);
            }
        }
        
        [Browsable(false), DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden), WebSysDescription("Repeater_Items")]
        public virtual RepeaterItemCollection Items
        {
            get
            {
                if (this.itemsCollection == null)
                {
                    if (this.itemsArray == null)
                    {
                        this.EnsureChildControls();
                    }
                    this.itemsCollection = new RepeaterItemCollection(this.itemsArray);
                }
                return this.itemsCollection;
            }
        }
        
        [PersistenceMode(PersistenceMode.InnerProperty), Browsable(false), TemplateContainer(typeof(RepeaterItem)), WebSysDescription("Repeater_ItemTemplate"), DefaultValue((string) null)]
        public virtual ITemplate ItemTemplate
        {
            get
            {
                return this.itemTemplate;
            }
            set
            {
                this.itemTemplate = value;
            }
        }
        
        protected bool RequiresDataBinding
        {
            get
            {
                return this._requiresDataBinding;
            }
            set
            {
                this._requiresDataBinding = value;
            }
        }
        
        protected DataSourceSelectArguments SelectArguments
        {
            get
            {
                if (this._arguments == null)
                {
                    this._arguments = this.CreateDataSourceSelectArguments();
                }
                return this._arguments;
            }
        }
        
        [WebSysDescription("Repeater_SeparatorTemplate"), PersistenceMode(PersistenceMode.InnerProperty), TemplateContainer(typeof(RepeaterItem)), Browsable(false), DefaultValue((string) null)]
        public virtual ITemplate SeparatorTemplate
        {
            get
            {
                return this.separatorTemplate;
            }
            set
            {
                this.separatorTemplate = value;
            }
        }
    }
}
顾晓北 | 园豆:10898 (专家六级) | 2013-03-28 11:50
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册