To learn more about this article, we recommend that you first preview "dynamically changing the name of the GridView control column" at http://www.cnblogs.com/insus/p/3232057.html. In any case, it can change the column title of the GridView. However, we still cannot understand how to dynamically bind data rows from that article, because we do not want to write too much html markup for controls that dynamically implement rendering.
Okay, I will share my methods with Insus. NET. The following example: how to achieve the data row conversion column display http://www.cnblogs.com/insus/p/3300818.html to the end, or
If AutoGenerateColumns = "false" is added. We have to manually present the data columns to be displayed. In the preceding example, all columns are dynamically obtained. Manual binding is impossible. It seems a little contradictory. Therefore, Insus. NET has the idea of writing this article.
To be honest, Insus. NET took some detours at the beginning to achieve this function, that is, to dynamically load the title of GridVeiw, load it, and then want to dynamically load data rows. However, when loading data dynamically, it still gets stuck and does not work. Eventually still give up this idea, change and refer to the dynamic for the GridView control to create columns dynamic http://www.cnblogs.com/insus/archive/2011/06/10/2077538.html to create a GridView column. After a column is rendered, it is rendered again. This can be seen from the point of view.
Next we will create a column template to implement a System. Web. UI. ITemplate interface.
Now we can go to the. aspx. cs code on the webpage where the GridView control is located to write programs. What we need to do is to obtain all column names from the Data source:
Prepare everything. We can dynamically bind the Header and Template below:
The override OnInit () method in the webpage dynamically generates a custom DynamicColumn template column. And pass each column name to DynamicColumn.
Demo: