smorhaim
smorhaim

Reputation: 798

How to merge columns using Telerik RadGrid control

I know I need to use Template Columns, but I am not clearly understanding how to use it.

I have a datasource which returns a collection, I can assign each property in the collection to a column.

But how do I:

A simple codebehind example will help. All I can find are very complex controls and stuff for examples..

Thank you.

Upvotes: 5

Views: 10632

Answers (3)

Mike G
Mike G

Reputation: 1986

Assuming you can modify the class that is used in the collection, I would make a "display" property.

public string Prop1 { get; set; }
public string Prop2 { get; set; }

public string PropertiesFormatted
{
  get
  {
    return this.Prop1 + " - " + this.Prop2;
  }
}

You can then assign that to a bound column. I find that this is better since you won't have to worry about having the formatting different in different areas of the software. Basically, it allows for reuse.

The other way to do it would be to indeed create a template column and using binding expressions. You can find out about data binding expressions either on MSDN or in Telerik's help, but you're going to want to do something like this:

<telerik:GridTemplateColumn UniqueName="TemplateColumn">
  <ItemTemplate>
    <span><%# DataBinder.Eval(Container.DataItem, "Prop1") %> - <%# DataBinder.Eval(Container.DataItem, "Prop2") %></span>
  </ItemTemplate>
</telerik:GridTemplateColumn>

EDIT Here is a URL that will allow you to look at some Grid template stuff: http://www.telerik.com/help/aspnet-ajax/grdcustomizewithgridtemplatecolumn.html

Upvotes: 1

bodee
bodee

Reputation: 2674

You can also use calculated columns

<telerik:GridCalculatedColumn HeaderText="Test" UniqueName="Test" DataType="System.String"
     DataFields="Field1, Field2" Expression='{0} + " - " + {1}'></telerik:GridCalculatedColumn>

http://demos.telerik.com/aspnet-ajax/grid/examples/generalfeatures/calculatedcolumns/defaultcs.aspx

Upvotes: 4

Dick Lampard
Dick Lampard

Reputation: 2266

The only way that comes to my mind is to to use binding expressions for the properties and code-behind methods that return the results from the property methods through those binding expressions.

Upvotes: 0

Related Questions