Question

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:

  • Merge two columns? such as col.prop1 +' '+ col.prop2 ?
  • Execute some methods on the properties such as col.prop1.ToString(overloaded)

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

Thank you.

Was it helpful?

Solution

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

OTHER TIPS

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

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top