This is a migrated thread and some comments may be shown as answers.

Programmatically create GridTemplateColumns

1 Answer 114 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Mark Holdt
Top achievements
Rank 1
Mark Holdt asked on 22 Jan 2010, 07:42 AM
Dear Telerik team,

I would like to achieve the following:

within the RadGrid, programmatically add a "Name" column with a hyperlink that links to a certain page. How do I achieve this programmatically?

So far I have added columns via the GridBoundColumn without much trouble:
e.g.  GridBoundColumn pname2;
        pname2 = new GridBoundColumn();
        RadGrid1.MasterTableView.Columns.Add(pname2);
        pname2.DataField = "Total";
        pname2.HeaderText = "Total";

However, I would like to add a column that has a hyperlink property also set. I assume I will have to use a GridTemplateColumn; i.e.
  GridTemplateColumn pname;
        pname = new GridTemplateColumn();
        RadGrid1.MasterTableView.Columns.Add(pname);
        pname.DataField = "Name";
        pname.HeaderText = "Name";
....?

How do I achieve this?

Thank you
Mark

1 Answer, 1 is accepted

Sort by
0
Shinu
Top achievements
Rank 2
answered on 22 Jan 2010, 08:08 AM
Hello Mark,

To create a template dynamically, you must define a custom class that implements the ITemplate interface. Then you can assign an instance of this class to the ItemTemplate or EditTemplateTemplate property of the GridTemplateColumn object.

Checkout the 'Creating template columns programmatically' session in the following link.
Programmatic creation

-Shinu.
Tags
Grid
Asked by
Mark Holdt
Top achievements
Rank 1
Answers by
Shinu
Top achievements
Rank 2
Share this question
or