Dynamic Data Binding (GridView control Header and ItemTemplate)

Source: Internet
Author: User

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:


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.