Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to format cells in ASP.NET DetailsView

2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/02 Report--

This article shows you how to format cells in ASP.NET DetailsView. The content is concise and easy to understand. It will definitely make your eyes shine. I hope you can gain something through the detailed introduction of this article.

In ASP.NET DetailsView, we already know if the UnitPrice to be bound is higher than $75.00, now let's look at how to format UnitPrice by coding, we can modify a row of data by modifying DetailsViewID.Rows[index]; and we can access a cell by visiting DetailsViewID.Rows[index].Cells[index], so we can format the cell by modifying format-related properties

To access a row, we need to get the index of the row. The index starts from 0. UnitPrice is the 15th row in DetailsView. Assuming it is the 4th row, we can access it through ExpensiveProductsPriceInBoldItalic.Rows[4]. At this point we can display this line in bold, italic font with the following code

ExpensiveProductsPriceInBoldItalic.Rows[4].Font.Bold = true; ExpensiveProductsPriceInBoldItalic.Rows[4].Font.Italic = true;

however, this format labels and value if we only want to format values, and we need to apply formatting to that second cell of the current line, see the code below

ExpensiveProductsPriceInBoldItalic.Rows[4].Cells[1].Font.Bold = true; ExpensiveProductsPriceInBoldItalic.Rows[4].Cells[1].Font.Italic = true;

We can also display tags and style related information through StyleSheet, instead of formatting with a certain row and column, we use CSS to control the format, open Styles.css file, add a new Class named ExpensivePriceEmphasis according to the following code

CSS .ExpensivePriceEmphasis { font-weight: bold; font-style: italic; }

Then, in DataBound event, set CssClass of the unit to ExpensivePriceEmphasis, and add it in DataBound event processing.

When viewing Chai(cost less than $75.00), the price will be displayed in the normal format Figure 4), but when viewing Mishi Kobe Niku,(price $97.00) it will be displayed in the format we set (Figure 5)

ASP.NET DetailsView: Prices below $75.00 will be displayed in normal format

ASP.NET DetailsView: Prices above $75.00 will appear in bold, Italic font

DataBound event using FormView control

The steps for binding to FormView data are similar to those for DetailsView: create a DataBound event handler, declare the DataItem type property bound to the control, and then perform the binding. However, they update differently.

FormView does not include any bound columns or collections of rows, but instead it consists of a series of templates composed of several static HTML, Web controls, bound expressions. Adjusting the appearance of FormView involves adjusting one or more FormView templates

Let's use FormView to list product items like in the previous example, but this time we'll only display the names and units of products with units less than or equal to 10 in red font

The above is how to format cells in ASP.NET DetailsView. Have you learned any knowledge or skills? If you want to learn more skills or enrich your knowledge reserves, please pay attention to the industry information channel.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report