3 // Rafael Mizrahi <rafim@mainsoft.com>
4 // Erez Lotan <erezl@mainsoft.com>
5 // Vladimir Krasnov <vladimirk@mainsoft.com>
8 // Copyright (c) 2002-2005 Mainsoft Corporation.
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:
18 // The above copyright notice and this permission notice shall be
19 // included in all copies or substantial portions of the Software.
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.
31 using System.Web.UI.HtmlControls;
32 using System.Web.UI.WebControls;
33 using System.Collections;
39 /// Provides basic functionalities for testing System.Web.UI.Control derived classes.
41 public class GHTControlBase : GHTBaseWeb
43 #region "Data members"
44 protected Control m_cToTest; //The control that is currently being tested.
45 protected TextBox m_tbToValidate; //will be used by validation controls as the control to validate.
46 protected Item[] m_aDataSource; //Array data source to use in data bound objects.
47 protected DataTable m_dtDataSource;//DataTable data source to use in data bound objects.
48 protected ArrayList m_derivedTypes; //The array that wil contain all types that are derived from Control, and need to be tested.
49 protected long m_controlsCounter; //Used to generate a unique id for each of the controls created using GHTActiveSubTestControlClone
52 #region "Construction"
55 /// handles basic initialization of the page, and contents.
57 public GHTControlBase()
62 m_controlsCounter = 0;
67 protected Control TestedControl
74 public Type[] TypesToTest
78 return (System.Type[])(m_derivedTypes.ToArray(typeof(System.Type)));
85 /// Initializes all the derived types that need to be tested.
87 protected virtual void InitTypes()
89 m_derivedTypes = new ArrayList();
92 // typeof(System.Web.UI.PartialCachingControl), Excluded from test.
93 // typeof(System.Web.UI.StaticPartialCachingControl), Excluded from test.
94 // typeof(System.Web.UI.DataBoundLiteralControl), Excluded from test.
95 m_derivedTypes.Add(typeof(System.Web.UI.LiteralControl));
96 m_derivedTypes.Add(typeof(System.Web.UI.Page));
97 m_derivedTypes.Add(typeof(System.Web.UI.UserControl));
99 //System.Web.UI.HtmlControls:
100 m_derivedTypes.Add(typeof(System.Web.UI.HtmlControls.HtmlAnchor));
101 m_derivedTypes.Add(typeof(System.Web.UI.HtmlControls.HtmlButton));
102 // typeof(System.Web.UI.HtmlControls.HtmlForm), Excluded from test.
103 m_derivedTypes.Add(typeof(System.Web.UI.HtmlControls.HtmlGenericControl));
104 m_derivedTypes.Add(typeof(System.Web.UI.HtmlControls.HtmlImage));
105 m_derivedTypes.Add(typeof(System.Web.UI.HtmlControls.HtmlInputButton));
106 m_derivedTypes.Add(typeof(System.Web.UI.HtmlControls.HtmlInputCheckBox));
107 m_derivedTypes.Add(typeof(System.Web.UI.HtmlControls.HtmlInputFile));
108 m_derivedTypes.Add(typeof(System.Web.UI.HtmlControls.HtmlInputHidden));
109 m_derivedTypes.Add(typeof(System.Web.UI.HtmlControls.HtmlInputImage));
110 m_derivedTypes.Add(typeof(System.Web.UI.HtmlControls.HtmlInputRadioButton));
111 m_derivedTypes.Add(typeof(System.Web.UI.HtmlControls.HtmlInputText));
112 m_derivedTypes.Add(typeof(System.Web.UI.HtmlControls.HtmlSelect));
113 m_derivedTypes.Add(typeof(System.Web.UI.HtmlControls.HtmlTable));
114 m_derivedTypes.Add(typeof(System.Web.UI.HtmlControls.HtmlTableCell));
115 m_derivedTypes.Add(typeof(System.Web.UI.HtmlControls.HtmlTableRow));
116 m_derivedTypes.Add(typeof(System.Web.UI.HtmlControls.HtmlTextArea));
118 //System.Web.UI.WebControls basic:
119 m_derivedTypes.Add(typeof(System.Web.UI.WebControls.Button));
120 m_derivedTypes.Add(typeof(System.Web.UI.WebControls.CheckBox));
121 m_derivedTypes.Add(typeof(System.Web.UI.WebControls.HyperLink));
122 m_derivedTypes.Add(typeof(System.Web.UI.WebControls.Image));
123 m_derivedTypes.Add(typeof(System.Web.UI.WebControls.ImageButton));
124 m_derivedTypes.Add(typeof(System.Web.UI.WebControls.Label));
125 m_derivedTypes.Add(typeof(System.Web.UI.WebControls.LinkButton));
126 m_derivedTypes.Add(typeof(System.Web.UI.WebControls.Literal));
127 m_derivedTypes.Add(typeof(System.Web.UI.WebControls.Panel));
128 m_derivedTypes.Add(typeof(System.Web.UI.WebControls.PlaceHolder));
129 m_derivedTypes.Add(typeof(System.Web.UI.WebControls.RadioButton));
130 m_derivedTypes.Add(typeof(System.Web.UI.WebControls.TextBox));
132 //System.Web.UI.WebControls basic list controls:
133 m_derivedTypes.Add(typeof(System.Web.UI.WebControls.DropDownList));
134 m_derivedTypes.Add(typeof(System.Web.UI.WebControls.ListBox));
135 m_derivedTypes.Add(typeof(System.Web.UI.WebControls.RadioButtonList));
136 m_derivedTypes.Add(typeof(System.Web.UI.WebControls.CheckBoxList));
138 //System.Web.UI.WebControls validation controls:
139 #if KNOWN_BUG //BUG_NUM:935
140 m_derivedTypes.Add(typeof(System.Web.UI.WebControls.CompareValidator));
141 m_derivedTypes.Add(typeof(System.Web.UI.WebControls.CustomValidator));
142 m_derivedTypes.Add(typeof(System.Web.UI.WebControls.RangeValidator));
143 m_derivedTypes.Add(typeof(System.Web.UI.WebControls.RegularExpressionValidator));
144 m_derivedTypes.Add(typeof(System.Web.UI.WebControls.RequiredFieldValidator));
146 #if KNOWN_BUG //BUG_NUM:1195
147 m_derivedTypes.Add(typeof(System.Web.UI.WebControls.ValidationSummary));
149 //System.Web.UI.WebControls rich controls (currently not supported):
150 // m_derivedTypes.Add(typeof(System.Web.UI.WebControls.AdRotator));
151 // m_derivedTypes.Add(typeof(System.Web.UI.WebControls.Calendar));
153 //System.Web.UI.WebControls advanced list controls:
154 m_derivedTypes.Add(typeof(System.Web.UI.WebControls.DataGrid));
155 m_derivedTypes.Add(typeof(System.Web.UI.WebControls.DataGridItem));
156 m_derivedTypes.Add(typeof(System.Web.UI.WebControls.DataList));
157 m_derivedTypes.Add(typeof(System.Web.UI.WebControls.DataListItem));
158 m_derivedTypes.Add(typeof(System.Web.UI.WebControls.Repeater));
159 m_derivedTypes.Add(typeof(System.Web.UI.WebControls.RepeaterItem));
160 m_derivedTypes.Add(typeof(System.Web.UI.WebControls.Table));
161 m_derivedTypes.Add(typeof(System.Web.UI.WebControls.TableCell));
162 m_derivedTypes.Add(typeof(System.Web.UI.WebControls.TableHeaderCell));
163 m_derivedTypes.Add(typeof(System.Web.UI.WebControls.TableRow));
164 //m_derivedTypes.Add(typeof( System.Web.UI.WebControls.Xml));
168 /// Adds a control to page.
169 /// If the control is in the context of other control (Have a parent)
170 /// (e.g.) TableCell, then the parent control is added to the page.
172 /// <param name="a_toAdd">The control to add to the page.</param>
173 protected void GHTAddToActiveForm(Control a_toAdd)
175 if (a_toAdd.Parent == null)
177 GHTActiveForm.Controls.Add(a_toAdd);
181 GHTAddToActiveForm(a_toAdd.Parent);
187 /// Creates a control to test, and adds it to a new subtest.
189 /// <param name="ctrlType">Type of control to test.</param>
190 /// <param name="description">description to add to subtest.</param>
191 protected void GHTSubTestBegin(Type ctrlType, string description)
193 GHTSubTestBegin(ctrlType, description, true);
197 /// Creates a new subtest, and a control to test.
199 /// <param name="ctrlType">Type of control to test.</param>
200 /// <param name="description">description to add to subtest.</param>
201 /// <param name="a_AddToPage">Whether to add the control to the subtest continer.</param>
202 protected void GHTSubTestBegin(Type a_ctrlType, string description, bool a_addToPage)
204 base.GHTSubTestBegin(a_ctrlType.ToString() + ": " + description);
205 GHTActiveSubtestControlClone(a_ctrlType, a_addToPage);
208 /// Clones a control within its context, and adds it to the active subtest.
209 /// e.g. if the control is a table cell, then a table will be created to wrap the table cell.
210 /// The table will be added to the active subtest, and the cell will be referened by m_m_cToTest.
212 /// <param name="a_ctrlType">Type of control to test.</param>
213 /// <param name="a_addToPage">Whether to add the control to the subtest continer.</param>
214 protected void GHTActiveSubtestControlClone(Type a_ctrlType, bool a_addToPage)
216 if (IsListControlDerived(a_ctrlType))
218 m_cToTest = GetListControlDerived(a_ctrlType, a_addToPage);
220 else if (IsIterativeControlControl(a_ctrlType))
222 m_cToTest = GetIterativeControl(a_ctrlType, a_addToPage);
224 else if (IsIterativeControlControlItem(a_ctrlType))
226 m_cToTest = GetIterativeControlItem(a_ctrlType, a_addToPage);
228 else if (IsTableRelated(a_ctrlType))
230 m_cToTest = GetTableRelated(a_ctrlType, a_addToPage);
232 else if (IsHTMLTableRelated(a_ctrlType))
234 m_cToTest = GetHtmlTableRelated(a_ctrlType, a_addToPage);
238 m_cToTest = (Control)GHTElementClone(a_ctrlType);
241 GHTActiveSubTest.Controls.Add(m_cToTest);
244 HandleValidationControls();
245 HandleCausesValidation();
246 SetId(); //Set a unique id to the control.
250 /// checks if a given type is derived from ListControl, and thus should be bound to data in order to display content.
252 /// <param name="ctrlType">The type to test.</param>
253 /// <returns>True if the ctrlType is derived from ListControl, otherwise false.</returns>
254 private bool IsListControlDerived(Type ctrlType)
256 return ctrlType.IsSubclassOf(typeof(ListControl));
260 /// Creates a control of the specified type, if it is a ListControl derived, then bounds it to data source.
262 /// <param name="ctrlType">Type of control to create.</param>
263 private Control GetListControlDerived(Type ctrlType, bool a_AddToPage)
265 ListControl l_listcontrol = GHTElementClone(ctrlType) as ListControl;
266 if (l_listcontrol != null)
268 l_listcontrol.DataSource = m_aDataSource;
269 l_listcontrol.DataTextField = "Description";
270 l_listcontrol.DataValueField = "Id";
271 l_listcontrol.DataBind();
274 GHTActiveSubTest.Controls.Add(l_listcontrol);
276 return l_listcontrol;
280 throw new ArgumentOutOfRangeException("ctrlType", ctrlType, "Must be a ListControl derived type.");
285 /// checks if a given type is an item of an iterative control, and thus should be checked in tis controls context.
287 /// <param name="ctrlType">The type to test.</param>
288 /// <returns>True if the ctrlType is an iteative control item, otherwise false.</returns>
289 private bool IsIterativeControlControlItem(Type ctrlType)
291 if ( ctrlType.Equals(typeof(RepeaterItem)))
295 else if (ctrlType.Equals(typeof(DataListItem)))
299 else if (ctrlType.Equals(typeof(DataGridItem)))
310 /// Creates an iterative control Item, included inside an iterative control..
312 /// <param name="ctrlType">Type of control to create.</param>
313 private Control GetIterativeControlItem(Type ctrlType, bool a_AddToPage)
315 if (ctrlType.Equals(typeof(RepeaterItem)))
317 Repeater l_rep = GetIterativeControl(typeof(Repeater), a_AddToPage) as Repeater;
319 return l_rep.Items[0];
322 if (ctrlType.Equals(typeof(DataListItem)))
324 DataList l_datalist = GetIterativeControl(typeof(DataList), a_AddToPage) as DataList;
326 return l_datalist.Items[0];
329 if (ctrlType.Equals(typeof(DataGridItem)))
331 DataGrid l_datagrid = GetIterativeControl(typeof(DataGrid), a_AddToPage) as DataGrid;
333 return l_datagrid.Items[0];
337 throw new ArgumentOutOfRangeException("ctrlType", ctrlType, "Allowed types are RepeaterItem, DataListItem or DataGridItem");
342 /// Checks if a given type is an iterative control, and thus should be boud to data.
344 /// <param name="ctrlType">The type to test.</param>
345 /// <returns>True if the ctrlType is an iteative control, otherwise false.</returns>
346 private bool IsIterativeControlControl(Type ctrlType)
348 if ( ctrlType.Equals(typeof(Repeater)))
352 else if (ctrlType.Equals(typeof(DataList)))
356 else if (ctrlType.Equals(typeof(DataGrid)))
367 /// Creates an iterative control.
369 /// <param name="ctrlType">Type of control to create.</param>
370 protected Control GetIterativeControl(Type ctrlType, bool a_AddToPage)
372 if (ctrlType.Equals(typeof(Repeater)))
374 Repeater l_rep = new Repeater();
375 l_rep.ItemTemplate = new RepeaterTemplate();
376 l_rep.DataSource = m_aDataSource;
380 GHTActiveSubTest.Controls.Add(l_rep);
384 else if (ctrlType.Equals(typeof(DataList)))
386 DataList l_dataList = new DataList();
387 l_dataList.ItemTemplate = new DataListTemplate();
388 l_dataList.DataSource = m_aDataSource;
389 l_dataList.DataBind();
392 GHTActiveSubTest.Controls.Add(l_dataList);
396 else if (ctrlType.Equals(typeof(DataGrid)))
398 DataGrid l_dataGrid = new DataGrid();
399 l_dataGrid.DataSource = m_dtDataSource;
400 l_dataGrid.DataBind();
403 GHTActiveSubTest.Controls.Add(l_dataGrid);
409 throw new ArgumentOutOfRangeException("ctrlType", ctrlType, "Allowed types are Repeater, DataList or DataGrid");
414 /// checks if a given type is a control that should be tested in the context of a HtmlTable.
416 /// <param name="ctrlType">The type to test.</param>
417 /// <returns>True if the ctrlType is a HtmlTable related type, otherwise false.</returns>
418 private bool IsHTMLTableRelated(Type ctrlType)
420 if ( ctrlType.Equals(typeof(HtmlTable)))
424 else if (ctrlType.Equals(typeof(HtmlTableRow)))
428 else if (ctrlType.Equals(typeof(HtmlTableCell)))
439 /// Creates a new table, and adds it to the GHTActivesubTest.
441 /// <param name="ctrlType">The type of the ctrl to test. must be one of </param>
442 /// <param name="description"></param>
443 /// <returns></returns>
444 protected Control GetHtmlTableRelated(Type ctrlType, bool a_AddToPage)
446 HtmlTable l_table = new HtmlTable();
447 HtmlTableRow l_row = new HtmlTableRow();
448 HtmlTableCell l_cell = new HtmlTableCell();
452 GHTActiveSubTest.Controls.Add(l_table);
454 l_table.Rows.Add(l_row);
455 l_row.Cells.Add(l_cell);
457 l_cell.InnerText = "Cell";
459 if ( l_table.GetType() == ctrlType)
463 else if (l_row.GetType() == ctrlType)
467 else if (l_cell.GetType() == ctrlType)
473 throw new ArgumentException("Should be HtmlTable related type.", "ctrlType = " + ctrlType.ToString() );
478 /// checks if a given type is a control that should be tested in the context of a table.
480 /// <param name="ctrlType">The type to test.</param>
481 /// <returns>True if the ctrlType is a table related type, otherwise false.</returns>
482 private bool IsTableRelated(Type ctrlType)
484 if ( ctrlType.Equals(typeof(Table)))
488 else if (ctrlType.Equals(typeof(TableRow)))
492 else if (ctrlType.Equals(typeof(TableCell)))
496 else if(ctrlType.Equals(typeof(TableHeaderCell)))
507 /// Creates a new table, and adds it to the GHTActivesubTest.
509 /// <param name="ctrlType">The type of the ctrl to test. must be one of </param>
510 /// <param name="description"></param>
511 /// <returns></returns>
512 protected Control GetTableRelated(Type ctrlType, bool a_AddToPage)
514 Table l_table = new Table();
515 TableRow l_headerRow = new TableRow();
516 TableRow l_row = new TableRow();
517 TableCell l_cell = new TableCell();
518 TableHeaderCell l_headerCell = new TableHeaderCell();
522 GHTActiveSubTest.Controls.Add(l_table);
525 l_table.Rows.Add(l_headerRow);
526 l_table.Rows.Add(l_row);
528 l_headerRow.Cells.Add(l_headerCell);
529 l_row.Cells.Add(l_cell);
531 l_headerCell.Text = "Header cell";
532 l_cell.Text = "Table cell";
534 if ( l_table.GetType() == ctrlType)
538 else if (l_row.GetType() == ctrlType)
542 else if (l_cell.GetType() == ctrlType)
546 else if(l_headerCell.GetType() == ctrlType)
552 throw new ArgumentException("Should be table related type.", "ctrlType = " + ctrlType.ToString() );
558 /// All validation controls must be assigned a control to validate before the page is loaded:
560 protected void HandleValidationControls(Control l_toTest)
562 BaseValidator l_validator = l_toTest as BaseValidator;
563 if (l_validator == null)
567 l_validator.ControlToValidate = "m_tbToValidate";
568 HandleCompareValidator(l_toTest);
571 /// All validation controls must be assigned a control to validate before the page is loaded:
573 protected void HandleValidationControls()
575 HandleValidationControls(m_cToTest);
579 /// Compare validator must have either ValueToCompare or ControlToCompare set, before the page is loaded.
581 private void HandleCompareValidator(Control l_cToTest)
583 CompareValidator l_compareValidator = l_cToTest as CompareValidator;
584 if (l_compareValidator == null)
588 l_compareValidator.ValueToCompare = "value to compare";
591 /// Compare validator must have either ValueToCompare or ControlToCompare set, before the page is loaded.
593 private void HandleCompareValidator()
595 HandleCompareValidator(m_cToTest);
599 /// Sets the causes validation property to false, if such a property exists in the m_cToTest.
600 /// This is needed because for controls that cause validation, the ValidationControls on the page
601 /// generate a client side script.
602 /// That feature is not working properly in GrassHopper, and is not the main issue of this test.
603 /// It will be testes specificly in the Validation control tests.
605 private void HandleCausesValidation()
608 HtmlButton hButton = m_cToTest as HtmlButton;
611 hButton.CausesValidation = false;
614 HtmlInputButton hInputButton = m_cToTest as HtmlInputButton;
615 if (hInputButton != null)
617 hInputButton.CausesValidation = false;
620 HtmlInputImage hInputImage = m_cToTest as HtmlInputImage;
621 if (hInputImage != null)
623 hInputImage.CausesValidation = false;
626 Button button = m_cToTest as Button;
629 button.CausesValidation = false;
632 ImageButton imageButton = m_cToTest as ImageButton;
633 if (imageButton != null)
635 imageButton.CausesValidation = false;
638 LinkButton linkButton = m_cToTest as LinkButton;
639 if (linkButton != null)
641 linkButton.CausesValidation = false;
645 /// Creates a textbox, and adds it to the page as not visable.
646 /// Creates a Required Field validator, and adds it to the page as not visible.
648 private void InitTbToValidate()
650 m_tbToValidate = new TextBox();
651 m_tbToValidate.Visible = false;
652 m_tbToValidate.ID = "m_tbToValidate";
653 this.Controls.Add(m_tbToValidate);
657 /// Creates the data sources to bind to.
659 private void InitDataSource()
666 /// Creates an array to be used as a data source.
668 private void InitDataArray()
670 m_aDataSource = new Item[] { new Item(1,"aaaa"),
677 /// creates a data table to be used as a data source.
679 private void InitDataTable()
681 m_dtDataSource = new DataTable("SourceTable");
683 DataColumn l_dcId = new DataColumn("Id", typeof(int));
684 DataColumn l_dcDescription = new DataColumn("Description", typeof(string));
686 m_dtDataSource.Columns.Add(l_dcId);
687 m_dtDataSource.Columns.Add(l_dcDescription);
689 for (int i=0; i<m_aDataSource.Length; i++)
691 DataRow l_drCurrent = m_dtDataSource.NewRow();
692 l_drCurrent["Id"] = m_aDataSource[i].Id;
693 l_drCurrent["Description"] = m_aDataSource[i].Description;
694 m_dtDataSource.Rows.Add(l_drCurrent);
699 /// Sets a unique unified id to the tested control based on the count of controls produced by this base.
707 /// Sets a unique unified id to a control based on the count of controls produced by this base.
709 private void SetId(Control a_toSet)
711 a_toSet.ID = "ctrl_" + m_controlsCounter.ToString();
717 /// Used as an array item, for the data source of data bound controls in this test.
721 #region "Construction"
722 public Item() : this(0, String.Empty)
726 public Item(int a_id, string a_description)
729 m_description = a_description;
733 #region "Data Members"
735 private string m_description;
751 public string Description
755 return m_description;
759 m_description = value;
766 public override string ToString()
768 return this.Id + " " + this.Description;
775 /// The templte used by repeater to render its items.
777 public class RepeaterTemplate : ITemplate
779 #region ITemplate Members
781 /// Implements ITemplate.instantiateIn(..)
782 /// Adds an item to the repeater.
784 /// <param name="a_container">The controls to add the templated item to.</param>
785 public void InstantiateIn(Control a_container)
789 Label l_lIdHeader = new Label();
790 l_lIdHeader.Text = "ID: ";
791 l_lIdHeader.Font.Bold = true;
792 Label l_lDescrptionHeader = new Label();
793 l_lDescrptionHeader.Text = " Description: ";
794 l_lDescrptionHeader.Font.Bold = true;
798 Label l_lIdData = new Label();
799 l_lIdData.DataBinding += new EventHandler(this.BindId);
800 Label l_lDescriptionData = new Label();
801 l_lDescriptionData.DataBinding += new EventHandler(this.BindDescription);
803 //The complete panel.
804 Panel l_pItemPanel = new Panel();
805 l_pItemPanel.Controls.Add(l_lIdHeader);
806 l_pItemPanel.Controls.Add(l_lIdData);
807 l_pItemPanel.Controls.Add(l_lDescrptionHeader);
808 l_pItemPanel.Controls.Add(l_lDescriptionData);
810 a_container.Controls.Add(l_pItemPanel);
815 /// Handles the data binding event of the Id label in the templated item.
817 /// <param name="sender">The source of the event.</param>
818 /// <param name="args">Additional information about the event.</param>
819 private void BindId(Object sender, EventArgs args)
821 Label l_lIddata = (Label)sender;
822 RepeaterItem l_riContainer = (RepeaterItem)l_lIddata.NamingContainer;
823 l_lIddata.Text = (DataBinder.Eval(l_riContainer.DataItem, "Id")).ToString();
827 /// Handles the data binding event of the Description label in the templated item.
829 /// <param name="sender">The source of the event.</param>
830 /// <param name="args">Additional information about the event.</param>
831 private void BindDescription(Object sender, EventArgs args)
833 Label l_lDescriptionData = (Label)sender;
834 RepeaterItem l_riContainer = (RepeaterItem)l_lDescriptionData.NamingContainer;
835 l_lDescriptionData.Text = (DataBinder.Eval(l_riContainer.DataItem, "Description")).ToString();
840 /// The templte used by DataList to render its items.
842 public class DataListTemplate : ITemplate
844 #region ITemplate Members
846 /// Implements ITemplate.instantiateIn(..)
847 /// Adds an item to the data list.
849 /// <param name="a_container">The controls to add the templated item to.</param>
850 public void InstantiateIn(Control a_container)
854 Label l_lIdHeader = new Label();
855 l_lIdHeader.Text = "ID: ";
856 l_lIdHeader.Font.Bold = true;
857 Label l_lDescrptionHeader = new Label();
858 l_lDescrptionHeader.Text = " Description: ";
859 l_lDescrptionHeader.Font.Bold = true;
863 Label l_lIdData = new Label();
864 l_lIdData.DataBinding += new EventHandler(this.BindId);
865 Label l_lDescriptionData = new Label();
866 l_lDescriptionData.DataBinding += new EventHandler(this.BindDescription);
868 //The complete panel.
869 Panel l_pItemPanel = new Panel();
870 l_pItemPanel.Controls.Add(l_lIdHeader);
871 l_pItemPanel.Controls.Add(l_lIdData);
872 l_pItemPanel.Controls.Add(l_lDescrptionHeader);
873 l_pItemPanel.Controls.Add(l_lDescriptionData);
875 a_container.Controls.Add(l_pItemPanel);
880 /// Handles the data binding event of the Id label in the templated item.
882 /// <param name="sender">The source of the event.</param>
883 /// <param name="args">Additional information about the event.</param>
884 private void BindId(Object sender, EventArgs args)
886 Label l_lIddata = (Label)sender;
887 DataListItem l_dliContainer = (DataListItem)l_lIddata.NamingContainer;
888 l_lIddata.Text = (DataBinder.Eval(l_dliContainer.DataItem, "Id")).ToString();
892 /// Handles the data binding event of the Description label in the templated item.
894 /// <param name="sender">The source of the event.</param>
895 /// <param name="args">Additional information about the event.</param>
896 private void BindDescription(Object sender, EventArgs args)
898 Label l_lDescriptionData = (Label)sender;
899 DataListItem l_dliContainer = (DataListItem)l_lDescriptionData.NamingContainer;
900 l_lDescriptionData.Text = (DataBinder.Eval(l_dliContainer.DataItem, "Description")).ToString();