Format cells in ASP. NET DetailsView

Source: Internet
Author: User
Tags italic font

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

 
 
  1. ExpensiveProductsPriceInBoldItalic.Rows[4].Font.Bold = true;  
  2.  
  3. 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

 
 
  1. ExpensiveProductsPriceInBoldItalic.Rows[4].Cells[1].Font.Bold = true;  
  2.  
  3. 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

 
 
  1. CSS  
  2.  
  3. .ExpensivePriceEmphasis   
  4.  
  5. {  
  6.  
  7.     font-weight: bold;  
  8.  
  9.     font-style: italic;  
  10.  
  11. }  
  12.  

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.

  1. ASP. NET 2.0 data Tutorial: Add and configure the ObjectDataSource Control
  2. ASP. NET 2.0 data Tutorial: add the Default. aspx page to each part
  3. ASP. NET 2.0 data Tutorial: Add breadcrumb navigation
  4. ASP. NET 2.0 data Tutorial: SiteMapDataSource Control
  5. ASP. NET 2.0 data Tutorial: Add a site map

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.