An important column type in the gridview control is templatefield. It can use the template to completely customize the column content.
Templatefield provides six different templates for customizing the specified area of the column, or creating the mode in which the cell in the column can enter, such as the editing mode. These templates are listed in table 7-6.
Table 7-6
Template Name |
description |
itemtemplate |
used to display an item in the templatefield of the data-bound control, common column |
alternatingitemtemplate |
used to display the replacement items of templatefield |
edititemtemplate |
used to display the templatefield entry in editing mode |
insertitemtemplate |
display the templatefield entry in insert mode |
headertemplate |
used to display the title of templatefield |
footertemplate |
used to display the script part of templatefield |
<Asp: boundfield datafield = "firstname" headertext = "firstname" sortexpression = "firstname"/> the new Code is as follows:
<Asp: templatefield headertext = "firstname" sortexpression = "firstname">
<Edititemtemplate>
<Asp: textbox id = "textbox1" runat = "server" text = '<% # BIND ("firstname") %>'> </ASP: textbox>
</Edititemtemplate>
<Itemtemplate>
<Asp: Label id = "label1" runat = "server" text = '<% # BIND ("firstname") %>'> </ASP: Label>
</Itemtemplate>
</ASP: templatefield>
As you can see, templatefield is divided into two templates-itemtemplate custom common templates use the lable label to display the data field firstname. When edititemtemplate is edited, the template displays the data field firstname In the textbox text box. you can see that both templates have <% # BIND ("fieldname") %> statements to specify the data fields to bind.