2
0

GHTDataListBase.cs 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238
  1. //
  2. // Authors:
  3. // Rafael Mizrahi <[email protected]>
  4. // Erez Lotan <[email protected]>
  5. // Vladimir Krasnov <[email protected]>
  6. //
  7. //
  8. // Copyright (c) 2002-2005 Mainsoft Corporation.
  9. //
  10. // Permission is hereby granted, free of charge, to any person obtaining
  11. // a copy of this software and associated documentation files (the
  12. // "Software"), to deal in the Software without restriction, including
  13. // without limitation the rights to use, copy, modify, merge, publish,
  14. // distribute, sublicense, and/or sell copies of the Software, and to
  15. // permit persons to whom the Software is furnished to do so, subject to
  16. // the following conditions:
  17. //
  18. // The above copyright notice and this permission notice shall be
  19. // included in all copies or substantial portions of the Software.
  20. //
  21. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  22. // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  23. // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  24. // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
  25. // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
  26. // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
  27. // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  28. //
  29. using System;
  30. using System.Collections;
  31. using System.ComponentModel;
  32. using System.Web;
  33. using System.Web.SessionState;
  34. using System.Web.UI;
  35. using System.Web.UI.WebControls;
  36. using System.Web.UI.HtmlControls;
  37. using GHTWebControls;
  38. using System.Drawing;
  39. using System.Data;
  40. namespace GHTTests
  41. {
  42. /// <summary>
  43. /// Summary description for GHTDataListBase.
  44. /// </summary>
  45. public class GHTDataListBase:GHTBaseWeb
  46. {
  47. BaseDataList mActiveDataList;
  48. public GHTDataListBase():base()
  49. {
  50. }
  51. #region Tests
  52. protected static DataTable GHTGetSampleDataSource()
  53. {
  54. DataTable SampleDT;
  55. SampleDT = new DataTable("Sample");
  56. DataColumn col = new DataColumn("colA",typeof(System.String));
  57. SampleDT.Columns.Add (col);
  58. col = new DataColumn("colB",typeof(System.Int32));
  59. SampleDT.Columns.Add (col);
  60. col = new DataColumn("colC",typeof(System.DateTime));
  61. SampleDT.Columns.Add (col);
  62. SampleDT.Rows.Add(new object[]{"row 1",11111,"01/01/2003"});
  63. SampleDT.Rows.Add(new object[]{"row 22222",2,"02/02/2004"});
  64. // SampleDT.Rows.Add(new object[]{"row 1",1});
  65. // SampleDT.Rows.Add(new object[]{"row 2",2});
  66. // }
  67. return SampleDT;
  68. }
  69. protected static DataSet GHTGetSampleDataSourceDS()
  70. {
  71. DataSet SampleDS = new DataSet("SampleDS");
  72. SampleDS.Tables.Add( GHTGetSampleDataSource());
  73. return SampleDS;
  74. }
  75. protected static string[] GHTGetSampleDataSourceArray()
  76. {
  77. return new string[]{"A","B","C"};
  78. }
  79. protected static Hashtable GHTGetSampleDataSourceCol()
  80. {
  81. Hashtable col = new Hashtable();
  82. col.Add ("Key A","Value A");
  83. col.Add ("Key B","Value B");
  84. col.Add ("Key C","Value C");
  85. return col;
  86. }
  87. #endregion
  88. protected void GHTBuildUnboundSampleDataList(BaseDataList ctl)
  89. {
  90. DataList lst = (DataList)ctl;
  91. lst.ItemTemplate = new MyItemTemplate();
  92. }
  93. protected void GHTBuildSampleDataList(BaseDataList ctl)
  94. {
  95. DataList lst = (DataList)ctl;
  96. lst.ItemTemplate = new MyItemTemplate();
  97. lst.DataSource = GHTGetSampleDataSource();
  98. lst.DataBind();
  99. }
  100. protected void GHTBuildUnboundSampleDataGrid(BaseDataList ctl)
  101. {
  102. DataGrid grid = (DataGrid)ctl;
  103. BoundColumn col = new BoundColumn();
  104. col.DataField = "colA";
  105. grid.Columns.Add(col);
  106. col = new BoundColumn();
  107. col.DataField = "colB";
  108. grid.Columns.Add(col);
  109. col = new BoundColumn();
  110. col.DataField = "colC";
  111. grid.Columns.Add(col);
  112. grid.AutoGenerateColumns =false;
  113. }
  114. protected void GHTBuildSampleDataGrid(BaseDataList ctl)
  115. {
  116. DataGrid grid = (DataGrid)ctl;
  117. BoundColumn col = new BoundColumn();
  118. col.DataField = "colA";
  119. grid.Columns.Add(col);
  120. col = new BoundColumn();
  121. col.DataField = "colB";
  122. grid.Columns.Add(col);
  123. col = new BoundColumn();
  124. col.DataField = "colC";
  125. grid.Columns.Add(col);
  126. grid.AutoGenerateColumns =false;
  127. col = new BoundColumn();
  128. grid.DataSource = GHTGetSampleDataSource();
  129. grid.DataBind();
  130. }
  131. private class MyItemTemplate : ITemplate
  132. {
  133. public void InstantiateIn(Control container )
  134. {
  135. TextBox ctl1 = new TextBox();
  136. ctl1.ID = "MyTextBox1";
  137. ctl1.DataBinding +=new EventHandler(BindColA);
  138. container.Controls.Add(ctl1);
  139. TextBox ctl2 = new TextBox();
  140. ctl2.ID = "MyTextBox2";
  141. ctl2.DataBinding +=new EventHandler(BindColB);
  142. container.Controls.Add(ctl2);
  143. }
  144. private void BindColA(Object sender ,EventArgs e )
  145. {
  146. TextBox ctl = (TextBox)sender;
  147. DataListItem DLI = (DataListItem)ctl.NamingContainer;
  148. DataRowView drv = (DataRowView)DLI.DataItem;
  149. ctl.Text = drv["colA"].ToString();
  150. }
  151. private void BindColB(Object sender ,EventArgs e )
  152. {
  153. TextBox ctl = (TextBox)sender;
  154. DataListItem DLI = (DataListItem)ctl.NamingContainer;
  155. DataRowView drv = (DataRowView)DLI.DataItem;
  156. ctl.Text = drv["colB"].ToString();
  157. }
  158. }
  159. private class DataSourceClass
  160. {
  161. private string mcolA;
  162. private string mcolB;
  163. private string mcolC;
  164. public DataSourceClass(string colA, string colB, string colC)
  165. {
  166. mcolA = colA;
  167. mcolB = colB;
  168. mcolC = colC;
  169. }
  170. internal string colA
  171. {
  172. get {return mcolA;}
  173. }
  174. internal string colB
  175. {
  176. get {return mcolB;}
  177. }
  178. internal string colC
  179. {
  180. get {return mcolC;}
  181. }
  182. }
  183. #region Private Methods
  184. // helper utility to create a new sub test
  185. private void GHTDataListSubTestBegin(Type ctrlType, string description)
  186. {
  187. mActiveDataList = (BaseDataList)GHTElementClone(ctrlType);
  188. GHTSubTestBegin(description);
  189. GHTActiveSubTest.Controls.Add(mActiveDataList);
  190. }
  191. #endregion
  192. }
  193. public class GHTDataListSampleClass
  194. {
  195. public string colA;
  196. public int colB;
  197. public DateTime colC;
  198. public GHTDataListSampleClass(string lcolA, int lcolB, DateTime lcolC)
  199. {
  200. colA = lcolA;
  201. colB = lcolB;
  202. colC = lcolC;
  203. }
  204. // public string colA
  205. // {
  206. // get{return mcolA;}
  207. // set {mcolA = value;}
  208. // }
  209. // public int colB
  210. // {
  211. // get{return mcolB;}
  212. // set {mcolB = value;}
  213. // }
  214. // public DateTime colC
  215. // {
  216. // get{return mcolC;}
  217. // set {mcolC = value;}
  218. // }
  219. }
  220. }