New to Telerik UI for ASP.NET AJAXStart a free 30-day trial

Inheriting Grid Columns

In some scenarios you may want to extend the default functionality of GridColumn (including additional properties for it, embedding extra controls in its cells, etc.). The proper way to accomplish this task is by inheriting the corresponding default GridColumn class (in your own class) and overriding the InitializeCell(cell, columnIndex,gridItem) method of that class. Thus you can reuse the custom configuration of your choice in all your grid instances in your application.The example below shows a basic approach how to redefine the object model for GridBoundColumn:

ASP.NET
<%@ Register tagprefix="custom" namespace="MyNamespace" %>
<telerik:RadGrid RenderMode="Lightweight" ID="RadGrid1" DataSourceID="SqlDataSource1" AllowPaging="True"
  AllowSorting="True" runat="server" AutoGenerateColumns="false">
  <MasterTableView DataKeyNames="CustomerID">
    <Columns>
      <custom:MyCustomColumn DataField="CustomerID" HeaderText="CustomerID">
      </custom:MyCustomColumn>
    </Columns>
  </MasterTableView>
</telerik:RadGrid>
<asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:NorthwindConnectionString %>"
   SelectCommand="SELECT * FROM [Customers]"></asp:SqlDataSource>

When inheriting grid columns in hierarchy, you need to override their Clone() method and copy the base properties as follows:

C#
public override GridColumn Clone()
{
    RequiredGridBoundColumn requiredGridBoundColumn = new RequiredGridBoundColumn();

    //you should override CopyBaseProperties if you have some column specific properties
    requiredGridBoundColumn.CopyBaseProperties(this);

    return requiredGridBoundColumn;
}

Note that we do not support issues with inherited versions of RadGrid and the purpose of this topic is to provide basic instructions how to inherit your custom grid columns from RadGrid.

Not finding the help you need?
Contact Support