Customize the appearance of the DataGrid

Source: Internet
Author: User

1. Select the columns to display:

By default, the columns we display in the DataGrid are the columns We query when executing the SQL query statement. What does this mean? If Select * from myTable is used, all columns are displayed. If Select field1 and field2 from mytable are used, only two columns are displayed. Therefore, to select the columns to be displayed in the Datagrid, the simplest method is not to modify attributes, but to modify SQL query statements.

Another small problem is that when designing a database, the field name is often in English. However, we want to use Chinese in the DataGrid, in the select statement, we need to give each field a Chinese alias, such As: Select Name as Name, cardid As employee number from mytable.

Sometimes it is inconvenient for us to use this method to select the columns we want to display, so we can use the property generator to set them.

In the design view, select the DataGrid, and the "Property generator" link will appear at the bottom of the "Property Window". Click this link (or find the columns attribute) to bring up a dialog box, you can use this dialog box to set the columns to be selected:

First, we remove the hooks before "automatically create columns at runtime". In this way, the system will not automatically create columns, but will only display the columns you bind.

Click "column" on the left, and "Bind Column" and "button column" appear on the right. here we want to select "Bind Column ". Add a binding column and fill in items such as "header text. The header text refers to the page title. enter the name of the field to be displayed in "data field. Then, you need to bind several fields and select several binding columns.

2. Modify the DataGrid Style

By default, the table drawn from the DataGrid is ugly, so I need to customize its style. Select the DataGrid, and a "auto apply format" link will appear at the bottom of the Property Window. Click this link to bring up a dialog box for you to select a format and select your desired format.

I don't know what you think. Anyway, I think there are two formats that match my appetite and comply with the company's design specifications, I often use these formats. If you are not satisfied, you need to customize it yourself. Customization is simple, that is, you can modify the attribute values of the "style" class. In addition, you can use the property generator to modify the style attributes. For example, if you do not want your table to return rows, you can go to the property generator, select "format", and then select "item" on the right ", remove the hooks before "text wrapping in cells" in each sub-item.

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.