RepeaterDesigner.cs 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161
  1. //
  2. // Permission is hereby granted, free of charge, to any person obtaining
  3. // a copy of this software and associated documentation files (the
  4. // "Software"), to deal in the Software without restriction, including
  5. // without limitation the rights to use, copy, modify, merge, publish,
  6. // distribute, sublicense, and/or sell copies of the Software, and to
  7. // permit persons to whom the Software is furnished to do so, subject to
  8. // the following conditions:
  9. //
  10. // The above copyright notice and this permission notice shall be
  11. // included in all copies or substantial portions of the Software.
  12. //
  13. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  14. // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  15. // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  16. // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
  17. // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
  18. // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
  19. // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  20. //
  21. /**
  22. * Namespace: System.Web.UI.Design.WebControls
  23. * Class: RepeaterDesigner
  24. *
  25. * Author: Gaurav Vaish
  26. * Maintainer: [email protected]
  27. *
  28. * (C) Gaurav Vaish (2002)
  29. */
  30. using System;
  31. using System.Collections;
  32. using System.Data;
  33. using System.Web.UI.WebControls;
  34. using System.Web.UI.Design;
  35. namespace System.Web.UI.Design.WebControls
  36. {
  37. public class RepeaterDesigner : ControlDesigner, IDataSourceProvider
  38. {
  39. private DataTable desTimeDataTable;
  40. private DataTable dummyDataTable;
  41. private Repeater repeater;
  42. public RepeaterDesigner()
  43. {
  44. }
  45. public string DataMember
  46. {
  47. get
  48. {
  49. return repeater.DataMember;
  50. }
  51. set
  52. {
  53. repeater.DataMember = value;
  54. }
  55. }
  56. public string DataSource
  57. {
  58. get
  59. {
  60. DataBinding db = DataBindings["DataSource"];
  61. if(db != null)
  62. return db.Expression;
  63. return String.Empty;
  64. }
  65. set
  66. {
  67. if(value == null || value.Length == 0)
  68. {
  69. DataBindings.Remove("DataSource");
  70. } else
  71. {
  72. DataBinding toSet = new DataBinding("DataSource",
  73. typeof(IEnumerable), value);
  74. toSet.Expression = value;
  75. DataBindings.Add(toSet);
  76. }
  77. OnDataSourceChanged();
  78. OnBindingsCollectionChanged("DataSource");
  79. }
  80. }
  81. public virtual void OnDataSourceChanged()
  82. {
  83. desTimeDataTable = null;
  84. }
  85. protected bool TemplateExists
  86. {
  87. get
  88. {
  89. return (repeater.ItemTemplate != null ||
  90. repeater.HeaderTemplate != null ||
  91. repeater.FooterTemplate != null ||
  92. repeater.AlternatingItemTemplate != null);
  93. }
  94. }
  95. protected IEnumerable GetDesignTimeDataSource(int minimumRows)
  96. {
  97. return GetDesignTimeDataSource(GetResolvedSelectedDataSource(),
  98. minimumRows);
  99. }
  100. protected IEnumerable GetDesignTimeDataSource(IEnumerable selectedDataSource,
  101. int minimumRows)
  102. {
  103. DataTable toDeploy = desTimeDataTable;
  104. if(toDeploy == null)
  105. {
  106. if(selectedDataSource != null)
  107. {
  108. desTimeDataTable = DesignTimeData.CreateSampleDataTable(
  109. selectedDataSource);
  110. toDeploy = desTimeDataTable;
  111. } else
  112. {
  113. if(dummyDataTable == null)
  114. dummyDataTable = DesignTimeData.CreateDummyDataTable();
  115. toDeploy = dummyDataTable;
  116. }
  117. }
  118. return DesignTimeData.GetDesignTimeDataSource(toDeploy,
  119. minimumRows);
  120. }
  121. protected override void Dispose(bool disposing)
  122. {
  123. if(disposing)
  124. repeater = null;
  125. base.Dispose(disposing);
  126. }
  127. public object GetSelectedDataSource()
  128. {
  129. object retVal = null;
  130. DataBinding db = DataBindings["DataSource"];
  131. if(db != null)
  132. {
  133. retVal = DesignTimeData.GetSelectedDataSource(repeater, db.Expression);
  134. }
  135. return retVal;
  136. }
  137. public virtual IEnumerable GetResolvedSelectedDataSource()
  138. {
  139. IEnumerable retVal = null;
  140. DataBinding db = DataBindings["DataSource"];
  141. if(db != null)
  142. {
  143. retVal = DesignTimeData.GetSelectedDataSource(repeater, db.Expression, DataMember);
  144. }
  145. return retVal;
  146. }
  147. }
  148. }