Dynamically change the HeaderTemplate column name of the Repeater control

Source: Internet
Author: User

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:


Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.