Business Pack Gridview - Dynamic gridViewTemplateColumn

Good day,

I have a GridView to which I’m currently dynamically adding anywhere between 1-19 columns. I was able to leverage one of your samples to achieve this, for which I’m grateful.

The users would like to add an image to each of the value cells in the grid with an image based on the value of the cell. e.g. 1-10 = {value Image1), 11-20 = {value Image2}, etc.

I’m battling to understand how to achieve this in code (i.e. instead of dynamically adding GridViewTextColumns, I want to dynamically add GridViewTemplateColumns).

Is there a way to do this?

I don’t know how to build a ContentTemplate in code.

This is the sort of result I’m looking for:

I think I’ll also need to create a HeaderTemplate for each column, because I need to display a modal dialog on the header click of the dynamic columns.

Kind regards,
Declan Kelly

it can be done, but it is a bit complicated because you’ll need to build your own binding expressions.

We have a sample repo with generating columns in GridView.

Basically, you will need to generate GridViewTemplateColumn controls, and use DelegateTemplate to define the templates for their headers and contents.
I recommend creating a separate control that will render the numeric value and the icon, so you can use it in the template and pass it just the value binding.

The headers may be more complicated as you will need to call a command binding there. The binding is probably going to look like this: _parent.SomeMethod("PropertyName"), so you can try to look at how we generate the command binding in DataPager.

Instead of _this, you will need to pass there the property name.