论Web控件开发 - 树状控件(二)

博客介绍了DropDownTree控件,其功能包括支持从DataTable载入数据、验证器控件、不同级别显示样式及叶子节点数据选择验证。还阐述了其开发原型,包含Items和ItemStyles两个集合属性,同时给出相关源代码,实现与WinPop相关类基本相同。

介绍完基础类及WinPop控件后下面开始介绍第一个控件DropDownTree。首先我先对该控件的功能作个介绍:

其界面如下:
DropDownTree.jpg
其功能如下:

    1.支持从DataTable中载入数据
    2.支持验证器控件
    3.支持不同级别显示样式
    4.支持仅针对叶子节点的数据选择验证

其开发原刑如下:

DropDownTreeUML.jpg

其中DropDownTree中含有两个集合属性,一个Items一个ItemStyles,Items中用来保存树状结构中的节点信息,而ItemStyles则保存不同级别的节点样式,在每一个Item中也会有一个ItemStyle属性,当Item的ItemStyle不为空时,系统才会取在DropDownTree中ItemStyles集合中的样式来绘制节点。而ItemStyles集合中根据集合中的索引来决定绘制级别的样式,如绘制根节点时将会取在ItemStyles[0]中的样式,而当节点级别大于ItemStyles集合中的条目时将取最后一个为绘制样式。另外在Item中也会有一个Items集合属性以此来实现树状结构。

以下是DropDownTreeItemStyle和DropDownTreeItemStyleCollection的源代码,他们的实现和WinPopItem和WinPopItemCollection的实现基本相同。

None.gifusing System;
None.gif
using System.Web.UI;
None.gif
using System.Web.UI.WebControls;
None.gif
using System.Web.UI.Design;
None.gif
using System.Drawing.Design;
None.gif
using System.Drawing;
None.gif
None.gif
using System.ComponentModel;
None.gif
using System.ComponentModel.Design;
None.gif
None.gif
namespace Keyss.WebControls
ExpandedBlockStart.gifContractedBlock.gif
dot.gif{    
InBlock.gif    [TypeConverter(
typeof(ExpandableObjectConverter))]
InBlock.gif    
public class DropDownTreeItemStyle:ViewStatePartBase
ExpandedSubBlockStart.gifContractedSubBlock.gif    
dot.gif{
ContractedSubBlock.gifExpandedSubBlockStart.gif        
const#region const
InBlock.gif        
public const string ForeColorKey = "A";
InBlock.gif        
public const string BackColorKey = "B";
ExpandedSubBlockEnd.gif        
#endregion

ContractedSubBlock.gifExpandedSubBlockStart.gif        
field#region field
InBlock.gif        [
InBlock.gif        Bindable(
true),
InBlock.gif        Category(
"Appearance"),
InBlock.gif        DefaultValue(
typeof(System.Drawing.Color),""),
InBlock.gif        NotifyParentProperty(
true),
InBlock.gif        TypeConverter(
typeof(WebColorConverter))
InBlock.gif        ]
InBlock.gif        
public  System.Drawing.Color ForeColor 
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif            
get
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{
InBlock.gif                
object o = ViewState[ForeColorKey];
InBlock.gif                
return(o==null)? System.Drawing.Color.Empty:(System.Drawing.Color)o;
ExpandedSubBlockEnd.gif            }

InBlock.gif            
set
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{
InBlock.gif                ViewState[ForeColorKey] 
= value;
ExpandedSubBlockEnd.gif            }

ExpandedSubBlockEnd.gif        }

InBlock.gif        [
InBlock.gif        Bindable(
true),
InBlock.gif        Category(
"Appearance"),
InBlock.gif        DefaultValue(
typeof(System.Drawing.Color),""),
InBlock.gif        NotifyParentProperty(
true),
InBlock.gif        TypeConverter(
typeof(WebColorConverter))
InBlock.gif        ]
InBlock.gif        
public  System.Drawing.Color BackColor 
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif            
get
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{
InBlock.gif                
object o = ViewState[BackColorKey];
InBlock.gif                
return(o==null)? System.Drawing.Color.Empty:(System.Drawing.Color)o;
ExpandedSubBlockEnd.gif            }

InBlock.gif            
set
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{
InBlock.gif                ViewState[BackColorKey] 
= value;
ExpandedSubBlockEnd.gif            }

ExpandedSubBlockEnd.gif        }

ExpandedSubBlockEnd.gif        
#endregion

ContractedSubBlock.gifExpandedSubBlockStart.gif        
render#region render
InBlock.gif        
public virtual void AddAttributesToRender(HtmlTextWriter writer)
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif            
if(this.ForeColor!=Color.Empty)
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{
InBlock.gif                writer.AddStyleAttribute(HtmlTextWriterStyle.Color,ColorTranslator.ToHtml(
this.ForeColor));
ExpandedSubBlockEnd.gif            }

InBlock.gif            
if(this.BackColor!=Color.Empty)
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{
InBlock.gif                writer.AddStyleAttribute(HtmlTextWriterStyle.BackgroundColor,ColorTranslator.ToHtml(
this.BackColor));
ExpandedSubBlockEnd.gif            }

ExpandedSubBlockEnd.gif        }

ExpandedSubBlockEnd.gif        
#endregion

ContractedSubBlock.gifExpandedSubBlockStart.gif        
copy merge#region copy merge
InBlock.gif        [EditorBrowsable(EditorBrowsableState.Never)]
InBlock.gif        
public virtual void CopyFrom(DropDownTreeItemStyle s)
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{    
InBlock.gif            
base.CopyFrom(s);
ExpandedSubBlockEnd.gif        }

InBlock.gif        [EditorBrowsable(EditorBrowsableState.Never)]
InBlock.gif        
public virtual void MergeWith(DropDownTreeItemStyle s)
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif            
base.MergeWith(s);
ExpandedSubBlockEnd.gif        }

ExpandedSubBlockEnd.gif        
#endregion

ExpandedSubBlockEnd.gif    }

ExpandedBlockEnd.gif}

None.gif

其中由于Style经常要作些Copy、Merge的操作因此重载了基类的MergeWith和CopyFrom方法,而为了方便样式的使用,系统定义了另外一个方法AddAttributesToRender,当在绘制Item时可以调用此方法来实现样式属性的输出。

None.gifusing System;
None.gif
using System.Web.UI;
None.gif
using System.Web.UI.WebControls;
None.gif
using System.Web.UI.Design;
None.gif
using System.Drawing.Design;
None.gif
using System.Drawing;
None.gif
using System.Collections;
None.gif
using System.ComponentModel;
None.gif
using System.ComponentModel.Design;
None.gif
None.gif
namespace Keyss.WebControls
ExpandedBlockStart.gifContractedBlock.gif
dot.gif{
InBlock.gif    [ 
InBlock.gif    PersistenceMode(PersistenceMode.InnerProperty),
InBlock.gif    ] 
InBlock.gif    
public class DropDownTreeItemStyleCollection:ViewStatePartCollectionBase
ExpandedSubBlockStart.gifContractedSubBlock.gif    
dot.gif{
InBlock.gif
InBlock.gif        
public int Add(DropDownTreeItemStyle item)
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif            
return base.AddItem(item);
ExpandedSubBlockEnd.gif        }

InBlock.gif        
public DropDownTreeItemStyle this[int index]
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif            
get 
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{
InBlock.gif                
if(index >= Count || index < 0)
ExpandedSubBlockStart.gifContractedSubBlock.gif                
dot.gif{
InBlock.gif                    
return null;
ExpandedSubBlockEnd.gif                }

InBlock.gif                
return (DropDownTreeItemStyle)this.InnerList[index];
ExpandedSubBlockEnd.gif            }

ExpandedSubBlockEnd.gif        }

InBlock.gif        
protected override ViewStatePartBase NewItem()
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif            
return new DropDownTreeItemStyle();
ExpandedSubBlockEnd.gif        }

InBlock.gif
ExpandedSubBlockEnd.gif    }

ExpandedBlockEnd.gif}

None.gif

DropDownTreeItemStyleCollection的实现和WinPopItemCollection的实现基本一样。

以下是DropDownTreeItem的实现

None.gifusing System;
None.gif
using System.Web.UI;
None.gif
using System.Web.UI.WebControls;
None.gif
using System.Web.UI.Design;
None.gif
using System.Drawing.Design;
None.gif
using System.Drawing;
None.gif
None.gif
using System.ComponentModel;
None.gif
using System.ComponentModel.Design;
None.gif
None.gif
namespace Keyss.WebControls
ExpandedBlockStart.gifContractedBlock.gif
dot.gif{
InBlock.gif    
public class DropDownTreeItem:ViewStatePartBase
ExpandedSubBlockStart.gifContractedSubBlock.gif    
dot.gif{
ContractedSubBlock.gifExpandedSubBlockStart.gif        
const#region const
InBlock.gif        
public const string TextKey = "A";
InBlock.gif        
public const string ValueKey = "B";
ExpandedSubBlockEnd.gif        
#endregion

ContractedSubBlock.gifExpandedSubBlockStart.gif        
public field#region public field
InBlock.gif        [
InBlock.gif        NotifyParentProperty(
true), 
InBlock.gif        Bindable(
true),
InBlock.gif        Category(
"Appearance"),
InBlock.gif        DefaultValue(
"")
InBlock.gif        ]
InBlock.gif        
public string Text 
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif
InBlock.gif            
get 
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif
InBlock.gif                
object o = ViewState[TextKey]; 
InBlock.gif                
return (o == null)?string.Empty : (string)o; 
ExpandedSubBlockEnd.gif            }
 
InBlock.gif            
set 
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif
InBlock.gif                ViewState[TextKey] 
= value;
ExpandedSubBlockEnd.gif            }
 
ExpandedSubBlockEnd.gif        }

InBlock.gif        [
InBlock.gif        NotifyParentProperty(
true), 
InBlock.gif        Bindable(
true),
InBlock.gif        Category(
"Appearance"),
InBlock.gif        DefaultValue(
"")
InBlock.gif        ]
InBlock.gif        
public string Value 
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif
InBlock.gif            
get 
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif
InBlock.gif                
object o = ViewState[ValueKey];
InBlock.gif                
return (o == null)?string.Empty:(string)o;
ExpandedSubBlockEnd.gif            }
 
InBlock.gif            
set 
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif
InBlock.gif                ViewState[ValueKey] 
= value; 
ExpandedSubBlockEnd.gif            }
 
ExpandedSubBlockEnd.gif        }

InBlock.gif
ExpandedSubBlockEnd.gif        
#endregion

ContractedSubBlock.gifExpandedSubBlockStart.gif        
DropDownTreeItemStyle#region DropDownTreeItemStyle
InBlock.gif        
protected DropDownTreeItemStyle _style;
InBlock.gif        [
InBlock.gif        NotifyParentProperty(
true),
InBlock.gif        PersistenceMode(PersistenceMode.Attribute),
InBlock.gif        DesignerSerializationVisibility(DesignerSerializationVisibility.Content),
InBlock.gif        TypeConverter(
typeof(ExpandableObjectConverter))
InBlock.gif        ]
InBlock.gif        
public virtual DropDownTreeItemStyle Style 
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif
InBlock.gif            
get 
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif
InBlock.gif                
if(_style == null
ExpandedSubBlockStart.gifContractedSubBlock.gif                
dot.gif{
InBlock.gif                    _style 
= new DropDownTreeItemStyle();
InBlock.gif                    
if(_isTrackingViewState)
InBlock.gif                        _style.TrackViewState();
ExpandedSubBlockEnd.gif                }

ExpandedSubBlockEnd.gif                
return _style; }
 
ExpandedSubBlockEnd.gif        }

InBlock.gif        [
InBlock.gif        DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden),
InBlock.gif        Browsable(
false),
InBlock.gif        ]
InBlock.gif        
protected virtual DropDownTreeItemStyle RenderStyle
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif            
get
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{
InBlock.gif                
if(!DropDownTree.ItemStyles.IsEmpty)
ExpandedSubBlockStart.gifContractedSubBlock.gif                
dot.gif{
InBlock.gif                    DropDownTreeItemStyle tmpStyle 
= new DropDownTreeItemStyle();
InBlock.gif                    
int tmpLevel = this.Level;
InBlock.gif
InBlock.gif                    
if(tmpLevel < DropDownTree.ItemStyles.Count)
ExpandedSubBlockStart.gifContractedSubBlock.gif                    
dot.gif{
InBlock.gif                        tmpStyle.CopyFrom(DropDownTree.ItemStyles[tmpLevel]);
ExpandedSubBlockEnd.gif                    }

InBlock.gif                    
else
ExpandedSubBlockStart.gifContractedSubBlock.gif                    
dot.gif{
InBlock.gif                        tmpStyle.CopyFrom(
this.DropDownTree.ItemStyles[DropDownTree.ItemStyles.Count - 1]);
ExpandedSubBlockEnd.gif                    }

InBlock.gif                    
if(!Style.IsEmpty)
ExpandedSubBlockStart.gifContractedSubBlock.gif                    
dot.gif{
InBlock.gif                        tmpStyle.CopyFrom(
this.Style);
ExpandedSubBlockEnd.gif                    }

InBlock.gif                    
return tmpStyle;
ExpandedSubBlockEnd.gif                }

InBlock.gif                
else
InBlock.gif                    
return this.Style;
ExpandedSubBlockEnd.gif            }

ExpandedSubBlockEnd.gif        }

ExpandedSubBlockEnd.gif        
#endregion

ContractedSubBlock.gifExpandedSubBlockStart.gif        
DropDownTree, Owner, Level#region DropDownTree, Owner, Level
InBlock.gif        
protected DropDownTree _dropDownTree;
InBlock.gif        
protected DropDownTreeItem _owner;
InBlock.gif        [
InBlock.gif        DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden),
InBlock.gif        Browsable(
false),
InBlock.gif        ]
InBlock.gif        
public DropDownTreeItem Owner
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
ExpandedSubBlockStart.gifContractedSubBlock.gif            
get dot.gif{return _owner;}
ExpandedSubBlockStart.gifContractedSubBlock.gif            
set dot.gif{_owner = value;}
ExpandedSubBlockEnd.gif        }

InBlock.gif        [
InBlock.gif        DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden),
InBlock.gif        Browsable(
false),
InBlock.gif        ]
InBlock.gif        
public DropDownTree DropDownTree
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
ExpandedSubBlockStart.gifContractedSubBlock.gif            
get dot.gif{return _dropDownTree;}
ExpandedSubBlockStart.gifContractedSubBlock.gif            
set dot.gif{_dropDownTree = value;}
ExpandedSubBlockEnd.gif        }

InBlock.gif        [
InBlock.gif        DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden),
InBlock.gif        Browsable(
false),
InBlock.gif        ]
InBlock.gif        
public int Level
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif            
get 
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{
InBlock.gif                
int i = 0;
InBlock.gif                DropDownTreeItem tmpOwner 
= this._owner;
InBlock.gif                
while(tmpOwner != null)
ExpandedSubBlockStart.gifContractedSubBlock.gif                
dot.gif{
InBlock.gif                    tmpOwner 
= tmpOwner.Owner;
InBlock.gif                    i
++;
ExpandedSubBlockEnd.gif                }

InBlock.gif                
return i;
ExpandedSubBlockEnd.gif            }

ExpandedSubBlockEnd.gif        }

InBlock.gif        [
InBlock.gif        DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden),
InBlock.gif        Browsable(
false),
InBlock.gif        ]
InBlock.gif        
public int Index
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif            
get 
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{
InBlock.gif                
if(this.Level != 0)
InBlock.gif                    
return this.Owner.Items.IndexOf(this);
InBlock.gif                
else
InBlock.gif                    
return this.DropDownTree.Items.IndexOf(this);
ExpandedSubBlockEnd.gif            }

ExpandedSubBlockEnd.gif        }

ExpandedSubBlockEnd.gif        
#endregion

ContractedSubBlock.gifExpandedSubBlockStart.gif        
Items#region Items
InBlock.gif        
private DropDownTreeItemCollection _items;
InBlock.gif        [
InBlock.gif        NotifyParentProperty(
true),
InBlock.gif        PersistenceMode(PersistenceMode.InnerProperty),
InBlock.gif        DesignerSerializationVisibility(DesignerSerializationVisibility.Content),
InBlock.gif        ]
InBlock.gif        
public DropDownTreeItemCollection Items
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif            
get 
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{
InBlock.gif                
if(_items == null
ExpandedSubBlockStart.gifContractedSubBlock.gif                
dot.gif{
InBlock.gif                    _items 
= new DropDownTreeItemCollection();
InBlock.gif                    
if(this._isTrackingViewState)
InBlock.gif                        _items.TrackViewState();
ExpandedSubBlockEnd.gif                }

InBlock.gif                
return _items;
ExpandedSubBlockEnd.gif            }

ExpandedSubBlockEnd.gif        }

ExpandedSubBlockEnd.gif        
#endregion
        
ContractedSubBlock.gifExpandedSubBlockStart.gif        
render#region render
InBlock.gif        
public virtual void Render(System.Web.UI.HtmlTextWriter writer)
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif            writer.WriteLine();
InBlock.gif            
this.AddAttributesToRender(writer);
InBlock.gif            writer.RenderBeginTag(HtmlTextWriterTag.Option);
InBlock.gif            
this.RenderContent(writer);
InBlock.gif            writer.RenderEndTag();
InBlock.gif            writer.WriteLine();
InBlock.gif            
this.Items.Render(writer);
ExpandedSubBlockEnd.gif        }

InBlock.gif        
protected virtual void AddAttributesToRender(System.Web.UI.HtmlTextWriter writer)
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif            
this.RenderStyle.AddAttributesToRender(writer);
InBlock.gif            
string tvalue = this.Value;
InBlock.gif            
if(this.DropDownTree.SelectLeafOnly&&(!this.Items.IsEmpty))
InBlock.gif                tvalue 
= string.Empty;
InBlock.gif            
if(tvalue!= string.Empty)
InBlock.gif                writer.AddAttribute(HtmlTextWriterAttribute.Value,tvalue);
InBlock.gif            
if(this.DropDownTree.SelectedValue == this.Value)
InBlock.gif                writer.AddAttribute(HtmlTextWriterAttribute.Selected,
"true");
ExpandedSubBlockEnd.gif        }

InBlock.gif        
protected virtual void RenderContent(System.Web.UI.HtmlTextWriter writer)
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{    
InBlock.gif            writer.Write(
string.Format("{0} {1}"this.GetTabText() + this.GetPreText(), this.Text));    
ExpandedSubBlockEnd.gif        }

InBlock.gif        
protected virtual string GetTabText()
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif            
if(this.Level == 0return string.Empty;
InBlock.gif            DropDownTreeItem pItem 
= this.Owner;
InBlock.gif            DropDownTreeItemCollection p_pItems;
InBlock.gif            
if(this.Level > 1)
InBlock.gif                p_pItems 
= pItem.Owner.Items;
InBlock.gif            
else
InBlock.gif                p_pItems 
= this.DropDownTree.Items;
InBlock.gif            
if(pItem.Index == p_pItems.Count-1)
InBlock.gif                
return string.Format("{0}{1}",pItem.GetTabText(), "&nbsp;&nbsp;&nbsp;&nbsp;" + this.DropDownTree.TabString);
InBlock.gif            
else
InBlock.gif                
return string.Format("{0}{1}",pItem.GetTabText(), "" + this.DropDownTree.TabString);
ExpandedSubBlockEnd.gif        }

InBlock.gif        
protected virtual string GetPreText()
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif            
int l = this.Level;
InBlock.gif            
int i = this.Index;
InBlock.gif
InBlock.gif            DropDownTreeItemCollection pItems;
InBlock.gif            
if(l == 0)
InBlock.gif                pItems 
= this.DropDownTree.Items;
InBlock.gif            
else
InBlock.gif                pItems 
= this.Owner.Items;
InBlock.gif
InBlock.gif            
if((l == 0)&&(pItems.Count == 1))
InBlock.gif                
return "";
InBlock.gif
InBlock.gif            
if((l == 0&& (i == 0&& (pItems.Count > 1))
InBlock.gif                
return "";
InBlock.gif
InBlock.gif            
if(i == (pItems.Count-1))
InBlock.gif                
return "";
InBlock.gif            
else
InBlock.gif                
return "";
ExpandedSubBlockEnd.gif        }

ExpandedSubBlockEnd.gif        
#endregion

ContractedSubBlock.gifExpandedSubBlockStart.gif        
IStateManager 成员#region IStateManager 成员
ContractedSubBlock.gifExpandedSubBlockStart.gif        
viewstate helper#region viewstate helper
InBlock.gif        
public override void SetDirty()
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif            
base.SetDirty ();
InBlock.gif            Style.SetDirty();
InBlock.gif            Items.SetDirty();
ExpandedSubBlockEnd.gif        }

ExpandedSubBlockEnd.gif        
#endregion

InBlock.gif        
public override void TrackViewState()
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif            
base.TrackViewState();
InBlock.gif            Style.TrackViewState();
InBlock.gif            Items.TrackViewState();
ExpandedSubBlockEnd.gif        }

InBlock.gif        
public override object SaveViewState()
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif            
object[] savedState = new object[3];
InBlock.gif            savedState[
0= base.SaveViewState();
InBlock.gif            savedState[
1= Style.SaveViewState();
InBlock.gif            savedState[
2= Items.SaveViewState();
InBlock.gif            
for(int i=0;i<savedState.Length;i++)
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{
InBlock.gif                
if(savedState[i] != null)
InBlock.gif                    
return savedState;
ExpandedSubBlockEnd.gif            }

InBlock.gif            
return null;
ExpandedSubBlockEnd.gif        }

InBlock.gif        
public override void LoadViewState(object state)
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif            
if(state !=null)
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{
InBlock.gif                
object[] savedState = (object[])state;
InBlock.gif
InBlock.gif                
if(savedState[0!= null)
InBlock.gif                    
base.LoadViewState(savedState[0]);
InBlock.gif                
if(savedState[1!= null)
InBlock.gif                    Style.LoadViewState(savedState[
1]);
InBlock.gif                
if(savedState[2!= null)
InBlock.gif                    Items.LoadViewState(savedState[
2]);
ExpandedSubBlockEnd.gif            }
    
ExpandedSubBlockEnd.gif        }

ExpandedSubBlockEnd.gif        
#endregion

ContractedSubBlock.gifExpandedSubBlockStart.gif        
Init#region Init
InBlock.gif        
public virtual void Init()
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif            
this.Items.Owner = this;
InBlock.gif            
this.Items.DropDownTree = this.DropDownTree;
InBlock.gif            
this.Items.Init();
ExpandedSubBlockEnd.gif        }

ExpandedSubBlockEnd.gif        
#endregion

ContractedSubBlock.gifExpandedSubBlockStart.gif        
load from table#region load from table
InBlock.gif        
public virtual void LoadFromDataRow(System.Data.DataRow row)
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif            System.Data.DataTable table 
= row.Table;
InBlock.gif
InBlock.gif            
if(table.Columns.Contains("Text"))
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{
InBlock.gif                
this.Text = row["Text"].ToString();
ExpandedSubBlockEnd.gif            }

InBlock.gif            
if(table.Columns.Contains("Value"))
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{
InBlock.gif                
this.Value = row["Value"].ToString();
ExpandedSubBlockEnd.gif            }

ExpandedSubBlockEnd.gif        }

ExpandedSubBlockEnd.gif        
#endregion

ExpandedSubBlockEnd.gif    }

ExpandedBlockEnd.gif}


以下是DropDownTreeItemCollection的源代码

None.gifusing System;
None.gif
using System.Web.UI;
None.gif
using System.Web.UI.WebControls;
None.gif
using System.Web.UI.Design;
None.gif
using System.Drawing.Design;
None.gif
using System.Drawing;
None.gif
using System.Collections;
None.gif
using System.ComponentModel;
None.gif
using System.ComponentModel.Design;
None.gif
namespace Keyss.WebControls
ExpandedBlockStart.gifContractedBlock.gif
dot.gif{
InBlock.gif    
public class DropDownTreeItemCollection:ViewStatePartCollectionBase
ExpandedSubBlockStart.gifContractedSubBlock.gif    
dot.gif{
ContractedSubBlock.gifExpandedSubBlockStart.gif        
DropDownTree, Owner, Level#region DropDownTree, Owner, Level
InBlock.gif        
protected DropDownTree _dropDownTree;
InBlock.gif        
protected DropDownTreeItem _owner;
InBlock.gif        [
InBlock.gif        DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden),
InBlock.gif        Browsable(
false),
InBlock.gif        ]
InBlock.gif        
public DropDownTreeItem Owner
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
ExpandedSubBlockStart.gifContractedSubBlock.gif            
get dot.gif{return _owner;}
ExpandedSubBlockStart.gifContractedSubBlock.gif            
set dot.gif{_owner = value;}
ExpandedSubBlockEnd.gif        }

InBlock.gif        [
InBlock.gif        DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden),
InBlock.gif        Browsable(
false),
InBlock.gif        ]
InBlock.gif        
public DropDownTree DropDownTree
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
ExpandedSubBlockStart.gifContractedSubBlock.gif            
get dot.gif{return _dropDownTree;}
ExpandedSubBlockStart.gifContractedSubBlock.gif            
set dot.gif{_dropDownTree = value;}
ExpandedSubBlockEnd.gif        }

InBlock.gif        [
InBlock.gif        DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden),
InBlock.gif        Browsable(
false),
InBlock.gif        ]
InBlock.gif        
public int Level
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif            
get 
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{
InBlock.gif                
int i = 0;
InBlock.gif                DropDownTreeItem tmpOwner 
= this._owner;
InBlock.gif                
while(tmpOwner != null)
ExpandedSubBlockStart.gifContractedSubBlock.gif                
dot.gif{
InBlock.gif                    tmpOwner 
= tmpOwner.Owner;
InBlock.gif                    i
++;
ExpandedSubBlockEnd.gif                }

InBlock.gif                
return i;
ExpandedSubBlockEnd.gif            }

ExpandedSubBlockEnd.gif        }

ExpandedSubBlockEnd.gif        
#endregion

ContractedSubBlock.gifExpandedSubBlockStart.gif        
collection#region collection
InBlock.gif        
public int Add(DropDownTreeItem item)
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{    
InBlock.gif            
return this.AddItem(item);
ExpandedSubBlockEnd.gif        }

InBlock.gif        
protected override int AddItem(ViewStatePartBase item)
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{        
InBlock.gif            DropDownTreeItem mItem 
= (DropDownTreeItem)item;
InBlock.gif            mItem.DropDownTree 
= this.DropDownTree;
InBlock.gif            mItem.Owner 
= this.Owner;
InBlock.gif            mItem.Init();
InBlock.gif            
return base.AddItem(mItem);
ExpandedSubBlockEnd.gif        }

InBlock.gif        
public DropDownTreeItem this[int index]
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif            
get 
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{
InBlock.gif                
if(index >= Count || index < 0)
ExpandedSubBlockStart.gifContractedSubBlock.gif                
dot.gif{
InBlock.gif                    
return null;
ExpandedSubBlockEnd.gif                }

InBlock.gif                
return (DropDownTreeItem)this.InnerList[index];
ExpandedSubBlockEnd.gif            }

ExpandedSubBlockEnd.gif        }

InBlock.gif        
public int IndexOf(DropDownTreeItem item)
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif            
return this.InnerList.IndexOf(item);
ExpandedSubBlockEnd.gif        }

InBlock.gif        
public DropDownTreeItem GetItemByValue(string _value)
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif            
if(!IsEmpty)
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{
InBlock.gif                
foreach(DropDownTreeItem item in this.InnerList)
ExpandedSubBlockStart.gifContractedSubBlock.gif                
dot.gif{
InBlock.gif                    
if(item.Value==_value)
InBlock.gif                        
return item;
InBlock.gif                    
else
ExpandedSubBlockStart.gifContractedSubBlock.gif                    
dot.gif{
InBlock.gif                        DropDownTreeItem item1 
= item.Items.GetItemByValue(_value);
InBlock.gif                        
if(item1!=null)
InBlock.gif                            
return item1;
ExpandedSubBlockEnd.gif                    }

ExpandedSubBlockEnd.gif                }

ExpandedSubBlockEnd.gif            }

InBlock.gif            
return null;
ExpandedSubBlockEnd.gif        }

ExpandedSubBlockEnd.gif        
#endregion

ContractedSubBlock.gifExpandedSubBlockStart.gif        
render#region render
InBlock.gif        
public virtual void Render(System.Web.UI.HtmlTextWriter writer)
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif            
if(!IsEmpty)
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{
InBlock.gif                
for(int i=0;i<this.Count;i++)
ExpandedSubBlockStart.gifContractedSubBlock.gif                
dot.gif{
InBlock.gif                    
this[i].Render(writer);
ExpandedSubBlockEnd.gif                }

ExpandedSubBlockEnd.gif            }

ExpandedSubBlockEnd.gif        }

ExpandedSubBlockEnd.gif        
#endregion

ContractedSubBlock.gifExpandedSubBlockStart.gif        
init#region init
InBlock.gif        
public virtual void Init()
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif            
for(int i = 0; i < this.Count; i ++)
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{
InBlock.gif                
this[i].DropDownTree = this.DropDownTree;
InBlock.gif                
this[i].Owner = this.Owner;
InBlock.gif                
this[i].Init();
ExpandedSubBlockEnd.gif            }

ExpandedSubBlockEnd.gif        }

ExpandedSubBlockEnd.gif        
#endregion

ContractedSubBlock.gifExpandedSubBlockStart.gif        
newitem#region newitem
InBlock.gif        
protected override ViewStatePartBase NewItem()
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif            
return new DropDownTreeItem();
ExpandedSubBlockEnd.gif        }

ExpandedSubBlockEnd.gif        
#endregion

ExpandedSubBlockEnd.gif    }

ExpandedBlockEnd.gif}

None.gif

最后是DropDownTree的代码
None.gifusing System;
None.gif
using System.Web.UI;
None.gif
using System.Web.UI.WebControls;
None.gif
using System.ComponentModel;
None.gif
None.gif
namespace Keyss.WebControls
ExpandedBlockStart.gifContractedBlock.gif
dot.gif{
InBlock.gif    [
InBlock.gif    ParseChildren(
true),
InBlock.gif    ValidationPropertyAttribute(
"SelectedValue"),
InBlock.gif    PersistChildren(
false),
InBlock.gif    DefaultProperty(
"Items"),
InBlock.gif    ToolboxData(
"<{0}:DropDownTree runat=server></{0}:DropDownTree>")]
InBlock.gif    
public class DropDownTree : System.Web.UI.WebControls.WebControl,IPostBackDataHandler
ExpandedSubBlockStart.gifContractedSubBlock.gif    
dot.gif{
ContractedSubBlock.gifExpandedSubBlockStart.gif        
loaddata from table#region loaddata from table
InBlock.gif        
public virtual void LoadFromTable(System.Data.DataTable table,bool isStr, string idField, string parentIDField)
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif            
try
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{
InBlock.gif                
this.Items.Clear();
InBlock.gif                System.Data.DataRow[] rows 
= table.Select(string.Format("{0} is null",parentIDField));
InBlock.gif                
foreach(System.Data.DataRow row in rows)
ExpandedSubBlockStart.gifContractedSubBlock.gif                
dot.gif{
InBlock.gif                    Keyss.WebControls.DropDownTreeItem item 
= new Keyss.WebControls.DropDownTreeItem();
InBlock.gif                    item.LoadFromDataRow(row);
InBlock.gif                    
this.Items.Add(item);
InBlock.gif                    LoadItemsFromTable(item, row[idField], table, isStr, idField, parentIDField);
ExpandedSubBlockEnd.gif                }

ExpandedSubBlockEnd.gif            }

InBlock.gif            
catch
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{
InBlock.gif                
throw new ArgumentException("Table or filed name error!",table.TableName);
ExpandedSubBlockEnd.gif            }

ExpandedSubBlockEnd.gif        }

InBlock.gif        
protected virtual void LoadItemsFromTable(DropDownTreeItem item, object idValue, System.Data.DataTable table,bool isStr,string idField, string parentIDField)
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif            
string selectStr;
InBlock.gif            
if(isStr)
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{
InBlock.gif                selectStr 
= "{0} = '{1}'";
ExpandedSubBlockEnd.gif            }

InBlock.gif            
else
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{
InBlock.gif                selectStr 
= "{0} = {1}";
ExpandedSubBlockEnd.gif            }

InBlock.gif
InBlock.gif            
try
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{
InBlock.gif                System.Data.DataRow[] rows 
= table.Select(string.Format(selectStr,parentIDField,idValue));
InBlock.gif                
foreach(System.Data.DataRow row in rows)
ExpandedSubBlockStart.gifContractedSubBlock.gif                
dot.gif{
InBlock.gif                    Keyss.WebControls.DropDownTreeItem item1 
= new Keyss.WebControls.DropDownTreeItem();
InBlock.gif                    item1.LoadFromDataRow(row);
InBlock.gif                    item.Items.Add(item1);
InBlock.gif                    LoadItemsFromTable(item1, row[idField], table, isStr, idField, parentIDField);
ExpandedSubBlockEnd.gif                }

ExpandedSubBlockEnd.gif            }

InBlock.gif            
catch
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{
InBlock.gif                
throw new ArgumentException("Table or filed name error!",table.TableName);
ExpandedSubBlockEnd.gif            }

ExpandedSubBlockEnd.gif        }

ExpandedSubBlockEnd.gif        
#endregion

ContractedSubBlock.gifExpandedSubBlockStart.gif        
public field#region public field
InBlock.gif        [
InBlock.gif        Bindable(
true),
InBlock.gif        Category(
"Appearance"),
InBlock.gif        DefaultValue(
"&nbsp;&nbsp;&nbsp;")
InBlock.gif        ]
InBlock.gif        
public string TabString 
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif
InBlock.gif            
get 
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif
InBlock.gif                
object o = ViewState["tabString"];
InBlock.gif                
return (o == null)?"&nbsp;&nbsp;&nbsp;":(string)o;
ExpandedSubBlockEnd.gif            }
 
InBlock.gif            
set 
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif
InBlock.gif                ViewState[
"tabString"= value; 
ExpandedSubBlockEnd.gif            }

ExpandedSubBlockEnd.gif        }

InBlock.gif        [
InBlock.gif        Bindable(
true),
InBlock.gif        Category(
"Appearance"),
InBlock.gif        DefaultValue(
"")
InBlock.gif        ]
InBlock.gif        
public string SelectedValue 
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif            
get 
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif
InBlock.gif                
object o = ViewState["selectedValue"];
InBlock.gif                
return (o == null)?"":(string)o;
ExpandedSubBlockEnd.gif            }
 
InBlock.gif            
set 
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif
InBlock.gif                ViewState[
"selectedValue"= value; 
ExpandedSubBlockEnd.gif            }

ExpandedSubBlockEnd.gif        }

InBlock.gif        [
InBlock.gif        DefaultValue(
false),
InBlock.gif        NotifyParentProperty(
true), 
InBlock.gif        ]
InBlock.gif        
public bool AutoPostBack 
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif
InBlock.gif            
get 
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif
InBlock.gif                
object o = ViewState["autoPostBack"];
InBlock.gif                
return (o == null)?false:(bool)o;
ExpandedSubBlockEnd.gif            }
 
InBlock.gif            
set 
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif
InBlock.gif                ViewState[
"autoPostBack"= value; 
ExpandedSubBlockEnd.gif            }
 
ExpandedSubBlockEnd.gif        }

InBlock.gif        [
InBlock.gif        DefaultValue(
false),
InBlock.gif        NotifyParentProperty(
true), 
InBlock.gif        ]
InBlock.gif        
public bool SelectLeafOnly
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif
InBlock.gif            
get 
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif
InBlock.gif                
object o = ViewState["selectLeafOnly"];
InBlock.gif                
return (o == null)?false:(bool)o;
ExpandedSubBlockEnd.gif            }
 
InBlock.gif            
set 
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif
InBlock.gif                ViewState[
"selectLeafOnly"= value; 
ExpandedSubBlockEnd.gif            }
 
ExpandedSubBlockEnd.gif        }

InBlock.gif        [
InBlock.gif        DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden),
InBlock.gif        Browsable(
false),
InBlock.gif        ]
InBlock.gif        
public DropDownTreeItem SelectedItem
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
ExpandedSubBlockStart.gifContractedSubBlock.gif            
get dot.gif{return this.Items.GetItemByValue(this.SelectedValue);}
ExpandedSubBlockEnd.gif        }

ExpandedSubBlockEnd.gif        
#endregion

ContractedSubBlock.gifExpandedSubBlockStart.gif        
DropDownTreeItemStyles#region DropDownTreeItemStyles
InBlock.gif        
private DropDownTreeItemStyleCollection _itemStyles;
InBlock.gif        [
InBlock.gif        NotifyParentProperty(
true),
InBlock.gif        PersistenceMode(PersistenceMode.InnerProperty),
InBlock.gif        DesignerSerializationVisibility(DesignerSerializationVisibility.Content),
InBlock.gif        ]
InBlock.gif        
public DropDownTreeItemStyleCollection ItemStyles
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif            
get 
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{
InBlock.gif                
if(_itemStyles==null
ExpandedSubBlockStart.gifContractedSubBlock.gif                
dot.gif{
InBlock.gif                    _itemStyles 
= new DropDownTreeItemStyleCollection();
InBlock.gif                    
if(this.IsTrackingViewState)
InBlock.gif                        _itemStyles.TrackViewState();
ExpandedSubBlockEnd.gif                }

InBlock.gif                
return _itemStyles;
ExpandedSubBlockEnd.gif            }

ExpandedSubBlockEnd.gif        }

ExpandedSubBlockEnd.gif        
#endregion

ContractedSubBlock.gifExpandedSubBlockStart.gif        
items#region items
InBlock.gif        
private DropDownTreeItemCollection _items;
InBlock.gif        [
InBlock.gif        NotifyParentProperty(
true),
InBlock.gif        PersistenceMode(PersistenceMode.InnerProperty),
InBlock.gif        DesignerSerializationVisibility(DesignerSerializationVisibility.Content),
InBlock.gif        ]
InBlock.gif        
public DropDownTreeItemCollection Items
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif            
get 
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{
InBlock.gif                
if(this._items ==null
ExpandedSubBlockStart.gifContractedSubBlock.gif                
dot.gif{
InBlock.gif                    _items 
= new DropDownTreeItemCollection();
InBlock.gif                    
if(this.IsTrackingViewState)
InBlock.gif                        _items.TrackViewState();
ExpandedSubBlockEnd.gif                }

InBlock.gif                
return _items;
ExpandedSubBlockEnd.gif            }

ExpandedSubBlockEnd.gif        }

ExpandedSubBlockEnd.gif        
#endregion

ContractedSubBlock.gifExpandedSubBlockStart.gif        
render#region render
InBlock.gif        
protected override void Render(HtmlTextWriter writer)
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif            
if(Page != null)
InBlock.gif                Page.VerifyRenderingInServerForm(
this);
InBlock.gif
InBlock.gif            
if(!Items.IsEmpty)
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{
InBlock.gif                
base.Render(writer);
ExpandedSubBlockEnd.gif            }

InBlock.gif            
else
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{
InBlock.gif                
if((this.Site!=null)&&this.Site.DesignMode)
InBlock.gif                    writer.WriteLine(
this.ID);
ExpandedSubBlockEnd.gif            }

ExpandedSubBlockEnd.gif        }

InBlock.gif        
protected override void RenderContents(HtmlTextWriter writer)
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif            
foreach(DropDownTreeItem item in this.Items)
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{
InBlock.gif                item.Render(writer);
ExpandedSubBlockEnd.gif            }

InBlock.gif
ExpandedSubBlockEnd.gif        }

InBlock.gif
InBlock.gif        
protected override HtmlTextWriterTag TagKey
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif            
get
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{
InBlock.gif                
return HtmlTextWriterTag.Select;
ExpandedSubBlockEnd.gif            }

ExpandedSubBlockEnd.gif        }

InBlock.gif        
protected override void AddAttributesToRender(HtmlTextWriter writer)
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif            
base.AddAttributesToRender (writer);
InBlock.gif            writer.AddAttribute(HtmlTextWriterAttribute.Name,
this.UniqueID);
InBlock.gif            
if(this.AutoPostBack)
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{
InBlock.gif                writer.AddAttribute(
"language","javascript");
InBlock.gif                writer.AddAttribute(
"onchange",this.Page.GetPostBackClientEvent(this,string.Empty));
ExpandedSubBlockEnd.gif            }

InBlock.gif
ExpandedSubBlockEnd.gif        }

InBlock.gif
ExpandedSubBlockEnd.gif        
#endregion

ContractedSubBlock.gifExpandedSubBlockStart.gif        
view State#region view State
InBlock.gif        
protected override void LoadViewState(object state)
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif            
if(state !=null)
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{
InBlock.gif                
object[] savedState = (object[])state;
InBlock.gif                
if(savedState[0!= null)
InBlock.gif                    
base.LoadViewState(savedState[0]);
InBlock.gif                
if(savedState[1!= null)
InBlock.gif                    ItemStyles.LoadViewState(savedState[
1]);
InBlock.gif                
if(savedState[2!= null)
InBlock.gif                    Items.LoadViewState(savedState[
2]);
ExpandedSubBlockEnd.gif            }
    
InBlock.gif
ExpandedSubBlockEnd.gif        }

InBlock.gif        
protected override object SaveViewState()
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif            
object[] savedState = new object[3];
InBlock.gif            savedState[
0= base.SaveViewState ();
InBlock.gif            savedState[
1= this.ItemStyles.SaveViewState();
InBlock.gif            savedState[
2= this.Items.SaveViewState();
InBlock.gif            
for(int i=0;i<savedState.Length;i++)
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{
InBlock.gif                
if(savedState[i] != null)
InBlock.gif                    
return savedState;
ExpandedSubBlockEnd.gif            }

InBlock.gif            
return null;
ExpandedSubBlockEnd.gif        }

InBlock.gif        
protected override void TrackViewState()
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif            
base.TrackViewState();
InBlock.gif            ItemStyles.TrackViewState();
InBlock.gif            Items.TrackViewState();
ExpandedSubBlockEnd.gif        }

ExpandedSubBlockEnd.gif        
#endregion

ContractedSubBlock.gifExpandedSubBlockStart.gif        
init#region init
InBlock.gif        
protected override void OnInit(EventArgs e)
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif            
base.OnInit (e);
InBlock.gif            
this.Items.Owner = null;
InBlock.gif            
this.Items.DropDownTree = this;
InBlock.gif            
this.Items.Init();
ExpandedSubBlockEnd.gif        }

ExpandedSubBlockEnd.gif        
#endregion

ContractedSubBlock.gifExpandedSubBlockStart.gif        
event#region event
InBlock.gif        
protected static readonly object EventSelectedIndexChanged = new object();
InBlock.gif        
public event System.EventHandler SelectedIndexChanged
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif            add
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{
InBlock.gif                Events.AddHandler(EventSelectedIndexChanged, value);
ExpandedSubBlockEnd.gif            }

InBlock.gif            remove
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{
InBlock.gif                Events.RemoveHandler(EventSelectedIndexChanged, value);
ExpandedSubBlockEnd.gif            }

ExpandedSubBlockEnd.gif        }

InBlock.gif        
protected virtual void OnSelectedIndexChanged(System.EventArgs e)
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif            EventHandler selectedIndexChangedHandler 
= (EventHandler)Events[EventSelectedIndexChanged];
InBlock.gif            
if(selectedIndexChangedHandler!=null)
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{
InBlock.gif                selectedIndexChangedHandler(
this,e);
ExpandedSubBlockEnd.gif            }

ExpandedSubBlockEnd.gif        }

ExpandedSubBlockEnd.gif        
#endregion

ContractedSubBlock.gifExpandedSubBlockStart.gif        
IPostBackDataHandler 成员#region IPostBackDataHandler 成员
InBlock.gif
InBlock.gif        
public void RaisePostDataChangedEvent()
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif            OnSelectedIndexChanged(System.EventArgs.Empty);
ExpandedSubBlockEnd.gif        }

InBlock.gif        
public bool LoadPostData(string postDataKey, System.Collections.Specialized.NameValueCollection postCollection)
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif            String presentValue 
= this.SelectedValue;
InBlock.gif            String postedValue 
= postCollection[this.UniqueID];
InBlock.gif
InBlock.gif            
if (presentValue == null || !presentValue.Equals(postedValue))
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{
InBlock.gif                
this.SelectedValue = postedValue;
InBlock.gif                
return true;
ExpandedSubBlockEnd.gif            }

InBlock.gif            
return false;
ExpandedSubBlockEnd.gif        }

ExpandedSubBlockEnd.gif        
#endregion

ExpandedSubBlockEnd.gif    }

ExpandedBlockEnd.gif}

None.gif
由于时间有限,今天先把代码贴上以后有空再加注解:),你们如果哪些看不懂可以帮我留言:)

转载于:https://www.cnblogs.com/keyss/archive/2005/01/08/88738.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值