Using custom code in Template Editor

I created a custom template for a column in a Data Grid that simply conists of a Label. The label is bound to a property of my data like this ${data.MyProperty}.

This works fine and the Grid now shows the value of the MyProperty as text.

Now I want to make some programmatic customizations to the text, e.g. display a different text, based on the actual value of the MyProperty (which is by the way of int type). Therefore I created a custom method in the Page.blazor.cs file:

public string MyMethod(int input)
{
return "Something"; // this is just dummy code!
}

In the expression that binds the MyProperty data to the label in the template editor of the grid column, I now use:

${MyMethod(data.MyProperty)}

This also works great (at runtime). But once I applied the change, the Grid in the Radzen visual editor is not shown any more. Instead a warning is shown:

The name 'MyMethod' does not exist in the current context Cannot convert lamda expression to intended delegate type because some of the return types in the block are not implicitly convertable to the delegate return type.

As said, at runtime it works, only in the designer it fails. Any ideas how to fix this?

Thanks!

Hi @JustJoe,

This is how Radzen's design time currently works. It will not recognize methods defined in a partial class. A possible workaround is to create the custom method in the page itself like this:

I am positive Radzen 3.0 will not need this workaround.

Hello @korchev,

thanks for your reply and for the proposal with the workaround. I tried it. It works, too, but the problem with the designer also remains here. It looks like that it does not matter if the method is defined in code behind or as "Property" in the page. In both cases, the designer will tell me that the name of "MyMethod" is unknown in the current context.

Looking forward to Radzen 3! :wink: