| |||||||||||||||||
Source File | Conditionals | Statements | Methods | TOTAL | |||||||||||||
Web\WebBuilders\ItemTemplates\TextTemplate.cs | - | 0,0 % | 0,0 % | 0,0 % |
|
1 | #region Copyright | |
2 | /* | |
3 | ShowX. Maps business objects into presentation layer. | |
4 | Copyright (C) 2005 Jesus Diaz. | |
5 | ||
6 | This library is free software; you can redistribute it and/or | |
7 | modify it under the terms of the GNU Lesser General Public | |
8 | License as published by the Free Software Foundation; either | |
9 | version 2.1 of the License, or (at your option) any later version. | |
10 | ||
11 | This library is distributed in the hope that it will be useful, | |
12 | but WITHOUT ANY WARRANTY; without even the implied warranty of | |
13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
14 | Lesser General Public License for more details. | |
15 | ||
16 | You should have received a copy of the GNU Lesser General Public | |
17 | License along with this library; if not, write to the Free Software | |
18 | Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. | |
19 | ||
20 | For project details see: http://showx.sourceforge.net | |
21 | */ | |
22 | #endregion | |
23 | ||
24 | using System; | |
25 | using System.Web.UI; | |
26 | using System.Web.UI.WebControls; | |
27 | ||
28 | namespace ShowX.Web.WebBuilders.ItemTemplates | |
29 | { | |
30 | /// <summary> | |
31 | /// This class is used to map the exact evaluation of a property onto the cell. | |
32 | /// The advantage of passing a string instead of a PropertyInfo is that you can | |
33 | /// use nested properties (i.e, populate cell with Property1.Property2 where | |
34 | /// Property1 is the name of a property in the ShowX object, and Property2 is the | |
35 | /// name of a property from the type returned by Property1). | |
36 | /// </summary> | |
37 | class TextTemplate : ITemplate { | |
38 | ||
39 | /// <summary> | |
40 | /// Name of the property(ies) to map | |
41 | /// </summary> | |
42 | protected string idPropertyName; | |
43 | ||
44 | /// <summary> | |
45 | /// Constructor for TextTemplate | |
46 | /// </summary> | |
47 | /// <param name="idPropertyName">Name of the property to map</param> | |
48 | 0 | public TextTemplate(string idPropertyName) |
49 | { | |
50 | this.idPropertyName = idPropertyName; | |
51 | } | |
52 | ||
53 | /// <summary> | |
54 | /// Method called when instantiating a TemplateColumn by using this | |
55 | /// ITemplate implementation | |
56 | /// </summary> | |
57 | /// <param name="container">Container that instantiate this Template</param> | |
58 | 0 | public void InstantiateIn(Control container) |
59 | { | |
60 | Literal lc = new Literal(); | |
61 | lc.DataBinding += new EventHandler(TemplateControl_DataBinding); | |
62 | container.Controls.Add(lc); | |
63 | } | |
64 | ||
65 | /// <summary> | |
66 | /// DataBinding Event related with a control of the template. Very useful to | |
67 | /// assign correct values to template controls. | |
68 | /// </summary> | |
69 | /// <param name="sender">Sender who invoke the data binding</param> | |
70 | /// <param name="e">Arguments of the event</param> | |
71 | 0 | private void TemplateControl_DataBinding(object sender, EventArgs e) |
72 | { | |
73 | Literal lc; | |
74 | lc = (Literal) sender; | |
75 | DataGridItem container = (DataGridItem) lc.NamingContainer; | |
76 | lc.Text += DataBinder.Eval(container.DataItem,idPropertyName); | |
77 | } | |
78 | } | |
79 | } | |
80 |
|