In ASP. in NET DetailsView, we already know whether the UnitPrice to be bound is higher than $75.00. Now let's see how to adjust the UnitPrice format by encoding. We can modify the DetailsViewID by modifying it. rows [index]; modifies a row of data, and we can access DetailsViewID. rows [index]. cells [index] to access a cell, so that we can Format this cell by modifying the format-related attributes.
To access a row, you need to obtain the index of a row. The index starts from 0 and UnitPrice is 15th rows in DetailsView. If it is in Row 4, we can use ExpensiveProductsPriceInBoldItalic. rows [4. at this time, we can use the following code to show this line as bold, italic font
- ExpensiveProductsPriceInBoldItalic.Rows[4].Font.Bold = true;
-
- ExpensiveProductsPriceInBoldItalic.Rows[4].Font.Italic = true;
However, this will format the Label and value. If we only want to format the value, and we need to apply the format to the second grid of the current row, please refer to the following code
- ExpensiveProductsPriceInBoldItalic.Rows[4].Cells[1].Font.Bold = true;
-
- ExpensiveProductsPriceInBoldItalic.Rows[4].Cells[1].Font.Italic = true;
We can also add a new Class named ExpensivePriceEmphasis through the StyleSheet sheet file according to the following code
- CSS
-
- .ExpensivePriceEmphasis
-
- {
-
- font-weight: bold;
-
- font-style: italic;
-
- }
-
Then, in the DataBound event, set the CssClass of the Unit to ExpensivePriceEmphasis and add
When you view Chai (the cost is lower than $75.00), the price is displayed in Figure 4 in the normal format, but when you view Mishi Kobe Niku (the price is $97.00) it will be displayed in the format we set (figure 5)
ASP. NET DetailsView: The price is lower than $75.00 and will be displayed in normal format
ASP. NET DetailsView: If the price is higher than $75.00, it is displayed in bold and Italic.
Use the DataBound event of the FormView Control
Similar to the steps for binding FormView data to DetailsView, you must create a DataBound event, declare the DataItem type attribute bound to the control, and then bind the data. However, they are updated in different ways.
FormView does not include any bound column or a set of rows. Instead, it is composed of a series of templates that contain several static HTML, Web controls, and binding expressions. Adjusting the appearance of a FormView involves adjusting one or more FormView templates.
Let's use FormView to list product items as in the previous example. But this time, we only use the red font to display the name and units of products whose units is less than or equal to 10.
- ASP. NET 2.0 data Tutorial: Add and configure the ObjectDataSource Control
- ASP. NET 2.0 data Tutorial: add the Default. aspx page to each part
- ASP. NET 2.0 data Tutorial: Add breadcrumb navigation
- ASP. NET 2.0 data Tutorial: SiteMapDataSource Control
- ASP. NET 2.0 data Tutorial: Add a site map