Dynamically create a DataGrid template column

xiaoxiao2021-03-06  35

Sometimes we need a complicated DataGrid, we know that DataGrid, DataList and other controls have a template column, and we can implement, complex logic's bonding through dynamic bonding template. Since Page inherits TemplateControl, you can use the method loadingTemplate in the templateControl class in the Page object. We can use this method to load the specified path user control to achieve a rich representation (by way of making a loadControl method and loadTemplate has the same Parameter type, that is, we can use the loadControl method to dynamically load user controls, you can implement custom user interfaces, divide the page elements into small user controls can be loaded according to the user's definition), we can also implement the Itemplate interface implementation Dynamic bonding of the column. 1. Using the loadTemplate implementation: Let's take an example, we create an ASP.NET web application, adding an ASCX user control called WebUserControl1.ascx as follows, only one Label control is only a label control in the user control A LastName field: <% @ Control language = "c #"%>

转载请注明原文地址:https://www.9cbs.com/read-64545.html

New Post(0)