asp.net 2.0 GridView Control Application Template

Source: Internet
Author: User
Tags button type

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

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.