Use templatefield Columns

Source: Internet
Author: User

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.

 

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.