GridTemplateColumn
Displays each item in the column in accordance with a specified templates (item, edit item, header and footer templates). This allows you to provide custom controls in the column.
You can view and set templates using the Edit Templates command in grid's Smart Tag.
You can also create the template columns programmatically and bind the controls in the code-behind (see Programmatic creation of Telerik RadGrid).
Note: Unlike other grid columns, GridTemplateColumn cannot be set as read-only.
Definition
Namespace:Telerik.Web.UI
Assembly:Telerik.Web.UI.dll
Syntax:
public class GridTemplateColumn : GridEditableColumn, IStateManager, IComparable, IGridEditableColumn, IGridDataColumn
Inheritance: objectGridColumnGridEditableColumnGridTemplateColumn
Implements:
Inherited Members
Example:
<radG:GridTemplateColumn UniqueName="TemplateColumn" SortExpression="CompanyName">
<FooterTemplate>
<img src="Img/image.gif" alt="" style="vertical-align: middle" />
Template footer
</FooterTemplate>
<HeaderTemplate>
<table id="Table1" cellspacing="0" cellpadding="0" width="300" border="1">
<tr>
<td colspan="2" align="center">
<b>Contact details</b></td>
</tr>
<tr>
<td style="width: 50%" align="center">
<asp:LinkButton CssClass="Button" Width="140" ID="btnContName" Text="Contact name"
ToolTip="Sort by ContactName" CommandName='Sort' CommandArgument='ContactName'
runat="server" /></td>
<td style="width: 50%" align="center">
<asp:LinkButton CssClass="Button" Width="140" ID="btnContTitle" Text="Contact title"
ToolTip="Sort by ContactTitle" CommandName='Sort' CommandArgument='ContactTitle'
runat="server" /></td>
</tr>
</table>
</HeaderTemplate>
<ItemTemplate>
<table cellpadding="1" cellspacing="1" class="customTable">
<tr>
<td style="width: 50%">
</%# Eval("ContactName") /%>
</td>
<td style="width: 50%">
</%# Eval("ContactTitle") /%>
</td>
</tr>
<tr>
<td colspan="2" align="center">
<a href='</%# "http://www.google.com/search?hl=en&q=" + DataBinder.Eval(Container.DataItem, "ContactName") + "&btnG=Google+Search"/%>'>
<em>Search Google for
</%# Eval("ContactName") /%>
</em></a>
</td>
</tr>
<tr>
<td colspan="2" align="center">
<img src="Img/image.gif" alt="" />
</td>
</tr>
</table>
</ItemTemplate>
</radG:GridTemplateColumn>
Constructors
public GridTemplateColumn()
Properties
Gets or sets the field name from the specified data source to bind to the GridTemplateColumn.
public virtual GridAggregateFunction Aggregate { get; set; }
A string, specifying the data field from the data source, from which to bind the column.
Gets or sets the HTML template of a RadGrid item when using client-side databinding.
[PersistenceMode(PersistenceMode.InnerProperty)]
public virtual string ClientItemTemplate { get; set; }
Gets or sets a string, specifying which DataField from the data source the control will use to handle the automatic filtering.
public virtual string DataField { get; set; }
A string, specifying which DataField from the data source the control will use to handle the automatic filtering.
Gets or sets the ItemTemplate, which is rendered in the control in edit mode.
[Browsable(false)]
[PersistenceMode(PersistenceMode.InnerProperty)]
[TemplateContainer(typeof(GridItem), BindingDirection.TwoWay)]
public virtual ITemplate EditItemTemplate { get; set; }
A value of type ITemplate
Sets or gets the format string for the footer/group footer aggregate.
public virtual string FooterAggregateFormatString { get; set; }
The format string for the footer/group footer aggregate.
Gets or sets the template, which will be rendered in the footer of the template column.
[Browsable(false)]
[PersistenceMode(PersistenceMode.InnerProperty)]
[TemplateContainer(typeof(GridItem))]
public virtual ITemplate FooterTemplate { get; set; }
A value of type ITemplate.
Gets or sets the template, which will be rendered in the header of the template column.
[Browsable(false)]
[PersistenceMode(PersistenceMode.InnerProperty)]
[TemplateContainer(typeof(GridItem), BindingDirection.TwoWay)]
public virtual ITemplate HeaderTemplate { get; set; }
A value of type ITemplate.
Set to false if templates should overwrite other controls in header cell (sort image, etc)
public bool InitializeTemplatesFirst { get; set; }
Gets or sets the ItemTemplate, which is rendered in the control in insert mode.
[Browsable(false)]
[PersistenceMode(PersistenceMode.InnerProperty)]
[TemplateContainer(typeof(GridItem), BindingDirection.TwoWay)]
public virtual ITemplate InsertItemTemplate { get; set; }
A value of type ITemplate
Gets a Boolean value, indicating whether the column is editable. If a template column is editable, it will render the contents of the EditItemTemplate in the edit form or InsertItemTemplate, if such defined, in the insert form. If there are no contents in the EditItemTemplate or InsertItemTemplate, the column will not be editable.
[Browsable(false)]
public override bool IsEditable { get; }
A Boolean value, indicating whether the column is editable.
Overrides:
Gets or sets the ItemTemplate, which is rendered in the control in normal (non-Edit) mode.
[Browsable(false)]
[PersistenceMode(PersistenceMode.InnerProperty)]
[TemplateContainer(typeof(GridItem), BindingDirection.TwoWay)]
public virtual ITemplate ItemTemplate { get; set; }
A value of type ITemplate
Methods
Creates a copy of the current column.
public override GridColumn Clone()
Overrides:
Note: When implementing/overriding this method be sure to call the base member or call CopyBaseProperties to be sure that all base properties will be copied accordingly
protected override void ColumnEditorChange(IGridColumnEditor newValue)
Overrides:
protected override void CopyBaseProperties(GridColumn fromColumn)
Overrides:
protected override IGridColumnEditor CreateDefaultColumnEditor()
Overrides:
Extracts the values from the editedItem and fills the names/values pairs for each data-field edited by the column in the newValues dictionary.
public override void FillValues(IDictionary newValues, GridEditableItem editableItem)
dictionary to fill. This param should not be null (Nothing in VB.NET)
editableItemGridEditableItemthe GridEditableItem to extract values from
Overrides:
This method should be used in case you develop your own column. It returns the full list of DataFields used by the column. GridTableView uses this to decide which DataFields from the specified DataSource will be inlcuded in case of GridTableView.RetrieveAllDataFields is set to false.
public override IDictionary GetCustomPropertyDataFields(object dataItemInstance)
Overrides:
Sets the value of the property CurrentFilterValue as a text on the TextBox control found in the cell
protected override void SetCurrentFilterValueToControl(TableCell cell)
Overrides:
This method should be used in case you develop your own column. It returns true if the column supports filtering.