TreeNode.cs 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802
  1. //
  2. // System.Web.UI.WebControls.TreeNode.cs
  3. //
  4. // Authors:
  5. // Lluis Sanchez Gual ([email protected])
  6. //
  7. // (C) 2004 Novell, Inc (http://www.novell.com)
  8. //
  9. // Permission is hereby granted, free of charge, to any person obtaining
  10. // a copy of this software and associated documentation files (the
  11. // "Software"), to deal in the Software without restriction, including
  12. // without limitation the rights to use, copy, modify, merge, publish,
  13. // distribute, sublicense, and/or sell copies of the Software, and to
  14. // permit persons to whom the Software is furnished to do so, subject to
  15. // the following conditions:
  16. //
  17. // The above copyright notice and this permission notice shall be
  18. // included in all copies or substantial portions of the Software.
  19. //
  20. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  21. // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  22. // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  23. // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
  24. // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
  25. // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
  26. // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  27. //
  28. // Copyright (C) 2004 Novell, Inc (http://www.novell.com)
  29. //
  30. #if NET_2_0
  31. using System;
  32. using System.Collections;
  33. using System.Text;
  34. using System.ComponentModel;
  35. using System.Web.UI;
  36. namespace System.Web.UI.WebControls
  37. {
  38. [ParseChildrenAttribute (true, "ChildNodes")]
  39. public class TreeNode: IStateManager, ICloneable
  40. {
  41. StateBag ViewState = new StateBag ();
  42. TreeNodeCollection nodes;
  43. bool marked;
  44. TreeView tree;
  45. TreeNode parent;
  46. int index;
  47. string path;
  48. int depth = -1;
  49. object dataItem;
  50. IHierarchyData hierarchyData;
  51. bool gotBinding;
  52. TreeNodeBinding binding;
  53. PropertyDescriptorCollection boundProperties;
  54. internal TreeNode (TreeView tree)
  55. {
  56. Tree = tree;
  57. }
  58. public TreeNode ()
  59. {
  60. }
  61. public TreeNode (string text)
  62. {
  63. Text = text;
  64. }
  65. public TreeNode (string text, string value)
  66. {
  67. Text = text;
  68. Value = value;
  69. }
  70. public TreeNode (string text, string value, string imageUrl)
  71. {
  72. Text = text;
  73. Value = value;
  74. ImageUrl = imageUrl;
  75. }
  76. public TreeNode (string text, string value, string imageUrl, string navigateUrl, string target)
  77. {
  78. Text = text;
  79. Value = value;
  80. ImageUrl = imageUrl;
  81. NavigateUrl = navigateUrl;
  82. Target = target;
  83. }
  84. [MonoTODO ("Not implemented")]
  85. protected TreeNode (TreeView owner, bool isRoot)
  86. {
  87. throw new NotImplementedException ();
  88. }
  89. [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
  90. [Browsable (false)]
  91. public int Depth {
  92. get {
  93. if (depth != -1) return depth;
  94. depth = 0;
  95. TreeNode nod = parent;
  96. while (nod != null) {
  97. depth++;
  98. nod = nod.parent;
  99. }
  100. return depth;
  101. }
  102. }
  103. void ResetPathData ()
  104. {
  105. path = null;
  106. depth = -1;
  107. gotBinding = false;
  108. }
  109. internal TreeView Tree {
  110. get { return tree; }
  111. set {
  112. if (SelectedFlag) {
  113. if (value != null)
  114. value.SetSelectedNode (this, false);
  115. if (tree != null)
  116. tree.SetSelectedNode (null, false);
  117. }
  118. tree = value;
  119. if (nodes != null)
  120. nodes.SetTree (tree);
  121. ResetPathData ();
  122. if (PopulateOnDemand && !Populated && Expanded.HasValue && Expanded.Value)
  123. Populate ();
  124. }
  125. }
  126. [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
  127. [DefaultValue (false)]
  128. [Browsable (false)]
  129. public bool DataBound {
  130. get { return ViewState ["DataBound"] == null ? false : (bool) ViewState ["DataBound"]; }
  131. private set { ViewState ["DataBound"] = value; }
  132. }
  133. [DefaultValue (null)]
  134. [Browsable (false)]
  135. public object DataItem {
  136. get {
  137. return dataItem;
  138. }
  139. }
  140. [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
  141. [DefaultValue ("")]
  142. [Browsable (false)]
  143. public string DataPath {
  144. get { return ViewState ["DataPath"] == null ? String.Empty : (String) ViewState ["DataPath"]; }
  145. private set { ViewState ["DataPath"] = value; }
  146. }
  147. [DefaultValue (false)]
  148. public bool Checked {
  149. get {
  150. object o = ViewState ["Checked"];
  151. if (o != null) return (bool)o;
  152. return false;
  153. }
  154. set {
  155. ViewState ["Checked"] = value;
  156. if (tree != null)
  157. tree.NotifyCheckChanged (this);
  158. }
  159. }
  160. [DefaultValue (null)]
  161. [MergableProperty (false)]
  162. [Browsable (false)]
  163. [PersistenceMode (PersistenceMode.InnerDefaultProperty)]
  164. public TreeNodeCollection ChildNodes {
  165. get {
  166. if (nodes == null) {
  167. nodes = new TreeNodeCollection (this);
  168. if (IsTrackingViewState)
  169. ((IStateManager)nodes).TrackViewState();
  170. }
  171. return nodes;
  172. }
  173. }
  174. [DefaultValue (null)]
  175. public bool? Expanded {
  176. get {
  177. object o = ViewState ["Expanded"];
  178. return (bool?)o;
  179. }
  180. set {
  181. bool? current = (bool?) ViewState ["Expanded"];
  182. if (current == value)
  183. return;
  184. ViewState ["Expanded"] = value;
  185. if (tree != null)
  186. tree.NotifyExpandedChanged (this);
  187. if (PopulateOnDemand && !Populated && value.HasValue && value.Value)
  188. Populate ();
  189. }
  190. }
  191. [Localizable (true)]
  192. [DefaultValue ("")]
  193. public string ImageToolTip {
  194. get {
  195. object o = ViewState ["ImageToolTip"];
  196. if (o != null) return (string)o;
  197. return "";
  198. }
  199. set {
  200. ViewState ["ImageToolTip"] = value;
  201. }
  202. }
  203. [DefaultValue ("")]
  204. [UrlProperty]
  205. [Editor ("System.Web.UI.Design.ImageUrlEditor, " + Consts.AssemblySystem_Design, typeof (System.Drawing.Design.UITypeEditor))]
  206. public string ImageUrl {
  207. get {
  208. object o = ViewState ["ImageUrl"];
  209. if (o != null) return (string)o;
  210. return "";
  211. }
  212. set {
  213. ViewState ["ImageUrl"] = value;
  214. }
  215. }
  216. [DefaultValue ("")]
  217. [UrlProperty]
  218. [Editor ("System.Web.UI.Design.UrlEditor, " + Consts.AssemblySystem_Design, typeof (System.Drawing.Design.UITypeEditor))]
  219. public string NavigateUrl {
  220. get {
  221. object o = ViewState ["NavigateUrl"];
  222. if (o != null) return (string)o;
  223. return "";
  224. }
  225. set {
  226. ViewState ["NavigateUrl"] = value;
  227. }
  228. }
  229. [DefaultValue (false)]
  230. public bool PopulateOnDemand {
  231. get {
  232. object o = ViewState ["PopulateOnDemand"];
  233. if (o != null) return (bool)o;
  234. return false;
  235. }
  236. set {
  237. ViewState ["PopulateOnDemand"] = value;
  238. }
  239. }
  240. [DefaultValue (TreeNodeSelectAction.Select)]
  241. public TreeNodeSelectAction SelectAction {
  242. get {
  243. object o = ViewState ["SelectAction"];
  244. if (o != null) return (TreeNodeSelectAction)o;
  245. return TreeNodeSelectAction.Select;
  246. }
  247. set {
  248. ViewState ["SelectAction"] = value;
  249. }
  250. }
  251. [DefaultValue (null)]
  252. public bool? ShowCheckBox {
  253. get {
  254. object o = ViewState ["ShowCheckBox"];
  255. return (bool?)o;
  256. }
  257. set {
  258. ViewState ["ShowCheckBox"] = value;
  259. }
  260. }
  261. internal bool ShowCheckBoxInternal {
  262. get {
  263. if (ShowCheckBox.HasValue)
  264. return ShowCheckBox.Value;
  265. else
  266. return (Tree.ShowCheckBoxes == TreeNodeTypes.All) ||
  267. ((Tree.ShowCheckBoxes & TreeNodeTypes.Leaf) > 0 && IsLeafNode) ||
  268. ((Tree.ShowCheckBoxes & TreeNodeTypes.Parent) > 0 && IsParentNode && Parent != null) ||
  269. ((Tree.ShowCheckBoxes & TreeNodeTypes.Root) > 0 && Parent == null && ChildNodes.Count > 0);
  270. }
  271. }
  272. [DefaultValue ("")]
  273. public string Target {
  274. get {
  275. object o = ViewState ["Target"];
  276. if(o != null) return (string)o;
  277. return "";
  278. }
  279. set {
  280. ViewState ["Target"] = value;
  281. }
  282. }
  283. [Localizable (true)]
  284. [DefaultValue ("")]
  285. [WebSysDescription ("The display text of the tree node.")]
  286. public string Text {
  287. get {
  288. object o = ViewState ["Text"];
  289. if (o != null) return (string)o;
  290. return "";
  291. }
  292. set {
  293. ViewState ["Text"] = value;
  294. }
  295. }
  296. [Localizable (true)]
  297. [DefaultValue ("")]
  298. public string ToolTip {
  299. get {
  300. object o = ViewState ["ToolTip"];
  301. if(o != null) return (string)o;
  302. return "";
  303. }
  304. set {
  305. ViewState ["ToolTip"] = value;
  306. }
  307. }
  308. [Localizable (true)]
  309. [DefaultValue ("")]
  310. public string Value {
  311. get {
  312. object o = ViewState ["Value"];
  313. if(o != null) return (string)o;
  314. return "";
  315. }
  316. set {
  317. ViewState ["Value"] = value;
  318. }
  319. }
  320. [DefaultValue (false)]
  321. public bool Selected {
  322. get {
  323. return SelectedFlag;
  324. }
  325. set {
  326. SelectedFlag = value;
  327. if (tree != null) {
  328. if (!value && tree.SelectedNode == this)
  329. tree.SetSelectedNode (null, false);
  330. else if (value)
  331. tree.SetSelectedNode (this, false);
  332. }
  333. }
  334. }
  335. internal virtual bool SelectedFlag {
  336. get {
  337. object o = ViewState ["Selected"];
  338. if(o != null) return (bool)o;
  339. return false;
  340. }
  341. set {
  342. ViewState ["Selected"] = value;
  343. }
  344. }
  345. [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
  346. [Browsable (false)]
  347. public TreeNode Parent {
  348. get { return parent; }
  349. }
  350. [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
  351. [Browsable (false)]
  352. public string ValuePath {
  353. get {
  354. if (tree == null) return Value;
  355. StringBuilder sb = new StringBuilder (Value);
  356. TreeNode node = parent;
  357. while (node != null) {
  358. sb.Insert (0, tree.PathSeparator);
  359. sb.Insert (0, node.Value);
  360. node = node.Parent;
  361. }
  362. return sb.ToString ();
  363. }
  364. }
  365. internal int Index {
  366. get { return index; }
  367. set { index = value; ResetPathData (); }
  368. }
  369. internal void SetParent (TreeNode node) {
  370. parent = node;
  371. ResetPathData ();
  372. }
  373. internal string Path {
  374. get {
  375. if (path != null) return path;
  376. StringBuilder sb = new StringBuilder (index.ToString());
  377. TreeNode node = parent;
  378. while (node != null) {
  379. sb.Insert (0, '_');
  380. sb.Insert (0, node.Index.ToString ());
  381. node = node.Parent;
  382. }
  383. path = sb.ToString ();
  384. return path;
  385. }
  386. }
  387. internal bool Populated {
  388. get {
  389. object o = ViewState ["Populated"];
  390. if (o != null) return (bool) o;
  391. return false;
  392. }
  393. set {
  394. ViewState ["Populated"] = value;
  395. }
  396. }
  397. internal bool HasChildData {
  398. get { return nodes != null; }
  399. }
  400. internal void Populate ()
  401. {
  402. if (tree == null)
  403. return;
  404. Populated = true;
  405. tree.NotifyPopulateRequired (this);
  406. }
  407. public void Collapse ()
  408. {
  409. Expanded = false;
  410. }
  411. public void CollapseAll ()
  412. {
  413. SetExpandedRec (false, -1);
  414. }
  415. public void Expand ()
  416. {
  417. Expanded = true;
  418. }
  419. internal void Expand (int depth)
  420. {
  421. SetExpandedRec (true, depth);
  422. }
  423. public void ExpandAll ()
  424. {
  425. SetExpandedRec (true, -1);
  426. }
  427. void SetExpandedRec (bool expanded, int depth)
  428. {
  429. Expanded = expanded;
  430. if (depth == 0) return;
  431. foreach (TreeNode nod in ChildNodes)
  432. nod.SetExpandedRec (expanded, depth - 1);
  433. }
  434. public void Select ()
  435. {
  436. Selected = true;
  437. }
  438. public void ToggleExpandState ()
  439. {
  440. #if TARGET_JVM //No support for Nullable<bool>.GetValueOrDefault() yet
  441. bool? value = Expanded;
  442. Expanded = value.HasValue ? !value.Value : true;
  443. #else
  444. Expanded = !Expanded.GetValueOrDefault(false);
  445. #endif
  446. }
  447. void IStateManager.LoadViewState (object savedState)
  448. {
  449. LoadViewState (savedState);
  450. }
  451. protected virtual void LoadViewState (object savedState)
  452. {
  453. if (savedState == null)
  454. return;
  455. object[] states = (object[]) savedState;
  456. ViewState.LoadViewState (states [0]);
  457. if (tree != null && SelectedFlag)
  458. tree.SetSelectedNode (this, true);
  459. if (!PopulateOnDemand || Populated)
  460. ((IStateManager)ChildNodes).LoadViewState (states [1]);
  461. }
  462. object IStateManager.SaveViewState ()
  463. {
  464. return SaveViewState ();
  465. }
  466. protected virtual object SaveViewState ()
  467. {
  468. object[] states = new object[2];
  469. states[0] = ViewState.SaveViewState();
  470. states[1] = (nodes == null ? null : ((IStateManager)nodes).SaveViewState());
  471. for (int i = 0; i < states.Length; i++) {
  472. if (states [i] != null)
  473. return states;
  474. }
  475. return null;
  476. }
  477. void IStateManager.TrackViewState ()
  478. {
  479. TrackViewState ();
  480. }
  481. protected void TrackViewState ()
  482. {
  483. if (marked) return;
  484. marked = true;
  485. ViewState.TrackViewState();
  486. if (nodes != null)
  487. ((IStateManager)nodes).TrackViewState ();
  488. }
  489. bool IStateManager.IsTrackingViewState {
  490. get { return IsTrackingViewState; }
  491. }
  492. protected bool IsTrackingViewState
  493. {
  494. get { return marked; }
  495. }
  496. internal void SetDirty ()
  497. {
  498. ViewState.SetDirty (true);
  499. if (nodes != null)
  500. nodes.SetDirty ();
  501. }
  502. public virtual object Clone ()
  503. {
  504. TreeNode nod = tree != null ? tree.CreateNode () : new TreeNode ();
  505. foreach (DictionaryEntry e in ViewState)
  506. nod.ViewState [(string)e.Key] = ((StateItem)e.Value).Value;
  507. foreach (TreeNode c in ChildNodes)
  508. nod.ChildNodes.Add ((TreeNode)c.Clone ());
  509. return nod;
  510. }
  511. object ICloneable.Clone () {
  512. return Clone ();
  513. }
  514. internal void Bind (IHierarchyData hierarchyData)
  515. {
  516. this.hierarchyData = hierarchyData;
  517. DataBound = true;
  518. DataPath = hierarchyData.Path;
  519. dataItem = hierarchyData.Item;
  520. TreeNodeBinding bin = GetBinding ();
  521. if (bin != null) {
  522. // Bind ImageToolTip property
  523. if (bin.ImageToolTipField.Length > 0) {
  524. ImageToolTip = Convert.ToString (GetBoundPropertyValue (bin.ImageToolTipField));
  525. if (ImageToolTip.Length == 0)
  526. ImageToolTip = bin.ImageToolTip;
  527. }
  528. else if (bin.ImageToolTip.Length > 0)
  529. ImageToolTip = bin.ImageToolTip;
  530. // Bind ImageUrl property
  531. if (bin.ImageUrlField.Length > 0) {
  532. ImageUrl = Convert.ToString (GetBoundPropertyValue (bin.ImageUrlField));
  533. if (ImageUrl.Length == 0)
  534. ImageUrl = bin.ImageUrl;
  535. }
  536. else if (bin.ImageUrl.Length > 0)
  537. ImageUrl = bin.ImageUrl;
  538. // Bind NavigateUrl property
  539. if (bin.NavigateUrlField.Length > 0) {
  540. NavigateUrl = Convert.ToString (GetBoundPropertyValue (bin.NavigateUrlField));
  541. if (NavigateUrl.Length == 0)
  542. NavigateUrl = bin.NavigateUrl;
  543. }
  544. else if (bin.NavigateUrl.Length > 0)
  545. NavigateUrl = bin.NavigateUrl;
  546. // Bind PopulateOnDemand property
  547. if (bin.HasPropertyValue ("PopulateOnDemand"))
  548. PopulateOnDemand = bin.PopulateOnDemand;
  549. // Bind SelectAction property
  550. if (bin.HasPropertyValue ("SelectAction"))
  551. SelectAction = bin.SelectAction;
  552. // Bind ShowCheckBox property
  553. if (bin.HasPropertyValue ("ShowCheckBox"))
  554. ShowCheckBox = bin.ShowCheckBox;
  555. // Bind Target property
  556. if (bin.TargetField.Length > 0) {
  557. Target = Convert.ToString (GetBoundPropertyValue (bin.TargetField));
  558. if (Target.Length == 0)
  559. Target = bin.Target;
  560. }
  561. else if (bin.Target.Length > 0)
  562. Target = bin.Target;
  563. // Bind Text property
  564. if (bin.TextField.Length > 0) {
  565. Text = Convert.ToString (GetBoundPropertyValue (bin.TextField));
  566. if (bin.FormatString.Length > 0)
  567. Text = string.Format (bin.FormatString, Text);
  568. if (Text.Length == 0)
  569. Text = bin.Text;
  570. if (Text.Length == 0)
  571. Text = bin.Value;
  572. if (Text.Length == 0 && bin.ValueField.Length > 0)
  573. Text = Convert.ToString (GetBoundPropertyValue (bin.ValueField));
  574. }
  575. else if (bin.Text.Length > 0)
  576. Text = bin.Text;
  577. else if (bin.Value.Length > 0)
  578. Text = bin.Value;
  579. else
  580. Text = GetDefaultBoundText ();
  581. // Bind ToolTip property
  582. if (bin.ToolTipField.Length > 0) {
  583. ToolTip = Convert.ToString (GetBoundPropertyValue (bin.ToolTipField));
  584. if (ToolTip.Length == 0)
  585. ToolTip = bin.ToolTip;
  586. }
  587. else if (bin.ToolTip.Length > 0)
  588. ToolTip = bin.ToolTip;
  589. // Bind Value property
  590. if (bin.ValueField.Length > 0) {
  591. Value = Convert.ToString (GetBoundPropertyValue (bin.ValueField));
  592. if (Value.Length == 0)
  593. Value = bin.Value;
  594. if (Value.Length == 0)
  595. Value = bin.Text;
  596. if(Value.Length == 0 && bin.TextField.Length > 0)
  597. Value = Convert.ToString (GetBoundPropertyValue (bin.TextField));
  598. }
  599. else if (bin.Value.Length > 0)
  600. Value = bin.Value;
  601. else if (bin.Text.Length > 0)
  602. Value = bin.Text;
  603. else if (Text.Length > 0)
  604. Value = Text;
  605. else
  606. Value = GetDefaultBoundText ();
  607. } else {
  608. Text = Value = GetDefaultBoundText ();
  609. }
  610. INavigateUIData navigateUIData = hierarchyData as INavigateUIData;
  611. if (navigateUIData != null) {
  612. Text = navigateUIData.ToString ();
  613. NavigateUrl = navigateUIData.NavigateUrl;
  614. }
  615. }
  616. internal void SetDataItem (object item)
  617. {
  618. dataItem = item;
  619. }
  620. internal void SetDataPath (string path)
  621. {
  622. DataPath = path;
  623. }
  624. internal void SetDataBound (bool bound)
  625. {
  626. DataBound = bound;
  627. }
  628. string GetDefaultBoundText ()
  629. {
  630. if (hierarchyData != null) return hierarchyData.ToString ();
  631. else if (dataItem != null) return dataItem.ToString ();
  632. else return string.Empty;
  633. }
  634. string GetDataItemType ()
  635. {
  636. if (hierarchyData != null) return hierarchyData.Type;
  637. else if (dataItem != null) return dataItem.GetType().ToString ();
  638. else return string.Empty;
  639. }
  640. internal bool IsParentNode {
  641. get { return ChildNodes.Count > 0 || (PopulateOnDemand && !Populated); }
  642. }
  643. internal bool IsLeafNode {
  644. get { return !IsParentNode; }
  645. }
  646. internal bool IsRootNode {
  647. get { return Depth == 0; }
  648. }
  649. TreeNodeBinding GetBinding ()
  650. {
  651. if (tree == null) return null;
  652. if (gotBinding) return binding;
  653. binding = tree.FindBindingForNode (GetDataItemType (), Depth);
  654. gotBinding = true;
  655. return binding;
  656. }
  657. object GetBoundPropertyValue (string name)
  658. {
  659. if (boundProperties == null) {
  660. if (hierarchyData != null)
  661. boundProperties = TypeDescriptor.GetProperties (hierarchyData);
  662. else
  663. boundProperties = TypeDescriptor.GetProperties (dataItem);
  664. }
  665. PropertyDescriptor prop = boundProperties.Find (name, true);
  666. if (prop == null)
  667. throw new InvalidOperationException ("Property '" + name + "' not found in data bound item");
  668. if (hierarchyData != null)
  669. return prop.GetValue (hierarchyData);
  670. else
  671. return prop.GetValue (dataItem);
  672. }
  673. internal void BeginRenderText (HtmlTextWriter writer)
  674. {
  675. RenderPreText (writer);
  676. }
  677. internal void EndRenderText (HtmlTextWriter writer)
  678. {
  679. RenderPostText (writer);
  680. }
  681. protected virtual void RenderPreText (HtmlTextWriter writer)
  682. {
  683. }
  684. protected virtual void RenderPostText (HtmlTextWriter writer)
  685. {
  686. }
  687. }
  688. }
  689. #endif