The GridView control is one of a series of data display controls that can be bound to the SqlDataSource control to dynamically generate a grid for the fields of the data records returned, and the GridView provides us with a variety of data-bound column types, such as BoundField The default data-bound column type is a simple data type that exhibits text data values.
Other types of data display text content alternating use, CheckBoxField check box display boolean data type, CommandField display a button, button type can be button General button, LinkButton Hyperlink button, ImageButton picture by button, and so on type, the GridView control also provides TemplateField, using templates. A template that can be customized for a data field, which can include a variety of static text, lable, textbox text boxes. In addition, there are various TemplateField templates that can be used to provide users with templates in different situations. For example, ItemTemplate display templates can be used to make display data, but EditItemTemplate edit templates can be used to make edits, HeaderTemplate custom header templates, FooterTemplate custom footer templates.
Today we're going to show you how to use TemplateField to set the appearance style of the GridView. The following example we use the GridView control to display the EmployeeID, LastName, and the Employees (employee table) under the Northwind database. Firtname, brthdote field, to list all employees, the employee's last name, first name (and the last name and name in the same grid) hire date, when we edit the data with the Calendar control display.
Create a new page, add a SqlDataSource control to the page in the design diagram to provide the data to be displayed for the GridView control, create a new connection, select local (Locals or.) from the data source configuration and use the SQL Servert mixed authentication mode, enter the user name, Password, select the database named Northwind and test the connection, save the connection string when the connection is successful, click Next button, select the Employees table in the Specify from table or view, select LastName, FirstName, Title in the Select column, HireDate and other fields. Click Advanced, select the Generate INSERT, UPDATE and DELETE statements and use optimistic concurrency check boxes, and then click Finish to complete the selection of the data.
Add the GridView control to the page, select SqlDataSource in the Convenience task panel, and then close the Convenience task panel. This creates a data-bound control. and set the AutoFormat for the GridView control. Save and run as shown in Figure 1,
Figure 1