Add columns to a datagrid dynamically


I want to click a button and then add a column to a datagrid (not use the 'visible property).

datagrid0.ColumnsCollection.Add() function may achieve my goal. Is there any demo to show how to do that? Thank you.

Hi @blu,

If this is related to your previous question:

Maybe it will be easier for you to create custom component similar to this article:

You will be able to use @foreach in the custom component razor markup.

Hi @enchev
Thank you for providing the solution.

I have further questions, how to trigger customComponent reload?

In the following test page, I think if I click the button to change the property "test", the customComponent should be reload, but it didn't happen.

I cannot comment since I don’t know how this reload is implemented.

Hi @enchev
I used the demo from custom component, and wanted to click a button to change the content, but failed. Following is what I have done, the pageTitle page is the same as demo. I think the content of child page should be updated when I click the button.

I've made an application to demonstrate you how to work with custom components. The custom component property Title is assigned as attribute bound to a page property that is changed on a button click.

Hi @enchev

Thank you so much for the demo. It works.