Today, we mainly look at the type of the gridview field. The gridview field types include boundfield, hyperlinkfield, commandfield, imagefield, and templatefield.
Boundfield:It indicates the fields displayed as text in the data binding control. You can set the header, style, and other information. Its dataformatstring can be used to set the format of the displayed field. For example, {0: c} indicates that the display format is currency type. 0 indicates the first parameter corresponding to the following parameter. Here is the value corresponding to the bound field. The symbol behind the colon is the format mark, which can display the data as the specified formatted data.
For example, we set the dataformatstring attribute for the unitprice column of the gridview.
The output result is as follows:
Hyperlinkfield:Fields displayed as hyperlinks, such as links to detailed pages.
Application Scenario: for example, you can use this method to link to the details page of a book from the book list page.
Operation Method:First, add hyperlinkfield and set the corresponding attributes.
In this way, the page will jump to default. aspx? Id = {0}. Of course, {0} will be replaced by the actual id value. In this way, we can pass the corresponding ID of the current book to the default. aspx page. On the default. aspx page, you can use request. querystring ["ID"] to obtain the id value for subsequent business operations.
Commandfield:A special field displays the command buttons used to select, edit, or delete an operation in the data binding control. Note that the command button correspondsCodeThey are all automatically generated and do not need to be handwritten.
If three layers of applications are used for writingProgramYou can use objectdatasource as the data source. If you use a common development method, you can use sqldatasource as the data source.
Note: For edit and delete operations, you must set the corresponding operation statement to take effect.
Imagefield: image field, bound to a field in the data source that contains the image URL.
Use dataimageurlformatstring to set the relative path to display the image of the corresponding field.
Templatefield: The field bound to the custom content. There are five templates (header, footer, common item, alternate item, and editing mode)
You must set the commandname attribute. If it is delete, it automatically Concatenates the delete statement to delete the selected item.
Of course, using data sources to bind data is not much used, but writing programs that you are interested in is still very efficient. Due to work needs, so here is a summary.
Use Cases of template columns: In what scenarios can we use template columns? When the bound field is an object, we can use the template column.
Now, we will discuss it here today. I hope this article will help you.