In this blog post, Insus. NET teaches you how to dynamically change the HeaderTemplate column name of the Repeater control. In general, there is no need for dynamic changes. Only when the dynamic Repeater control remains unchanged, multiple data sources are displayed for binding. In this way, you must dynamically change the HeaderTemplate column name or even the row or column information in the ItemTemplate.
Before implementing this function, we must first prepare the display of the regular Repeater control and bind it with the data. On the webpage, write the Repeater:
Go to. aspx. cs to bind the data source to the Repeater control:
View the results on the web page:
OK. Now we can dynamically display the HeaderTemplate information. To dynamically display the HeaderTemplate information, we need to modify the html code:
Comment out, and use Literal to replace them. On the Literal control, you can see the OnDataBinding event. Since this event is written, the logic process must be written in. aspx. cs.
The above code is written in line with line #37. The original table field name is obtained from the data source.
#40-#42 lines of code. All field names are generated cyclically. And dynamically generate columns.
Although it is a running state, the field name is still the original name. What if I want to change it to another alias?
Only the names of these columns are manually defined and placed in a collection. Instead, the highlighted lines of code are replaced:
Let's take a look: