In the recent period, many projects have to be written, and more personalized requirements of customers are required. For example, the field name obtained from the database needs to be changed to another name when it is displayed in the GridView. The following example uses similar data instead of the project content, but Insus. NET for demonstration.
First, create a webpage on the webpage of the site and pull the GridView control into the webpage. The field name originally displayed is blue-underlined.
In. cs:
OK, the program running result is as follows:
Now, we need to dynamically change the names of the columns in the simhei font, which are ID, Kind Name, and Fruit Name. What should I change to? This depends on the real requirements of the customer.
It has three columns in total. Therefore, we need to define the Field names of the three columns, which correspond one to one and put them in an array.
[] FieldNames = {,,};
The project environment of Insus. NET is obtained directly from the database. Because of the customization, the customer can easily change the corresponding name.
Next, there is the problem. How can we change it? This is the real problem. Go to the. aspx html page and add an event OnRowCreated = "GridViewFruit_RowCreated" in the GridView control ":
Go to. cs to write the Event Logic Program:
#1 is to determine whether it is the Header of the GridView.
#2 is the row where the Header is located.
#3 Add the Custom column name to the Header.
Run preview to see what it looks like:
The Custom column name appears. But the original column name still exists. How can this problem be solved? Think of it? The Grdiveiw control has a ShowHeader attribute that controls whether to display the Header of the GridView.
OK. Final effect:
Insus. NET hopes that this blog post will help you with your experience.