Tips on data-based display in gridview

Source: Internet
Author: User
During the data display process, we often modify the display format based on the displayed content to achieve the functions of prompting, emphasizing, or others. In the gridview, you can use the corresponding CSS to determine the data to achieve this effect. This method can be used in a series of template controls, such as detailsview, formview, and repeator.
Let's take a look:

In this gridview, the recommended movies on the home page are highlighted based on the value of the homepage recommendation. The method is as follows: first, bind the data in objectdatasource to the gridview normally, and preview it to see if it can display data normally. If the display is normal, proceed to the next step.
After each row is bound, the rowdatabound event is triggered. At this time, the bound data can be obtained through the gridviewroweventargs type parameter E. After obtaining the parameter, determine whether to apply CSS to it based on whether the value is true. Code As follows: Protected   Void Gridview1_rowdatabound ( Object Sender, gridviewroweventargs E)
{
If (E. Row. rowtype = Datacontrolrowtype. datarow)
{
Qmxmovie. movierow current = (Qmxmovie. movierow) (datarowview) E. Row. dataitem). row;
If (Current. Index) // Homepage recommendations
{
E. Row. cssclass= "Datarowemp";
}
}
}

Attach the corresponding CSS code:. Datarowemp
{}{
Background-color:# Bce3ff;

}

Haha, a few lines of code, a color scheme, helps you show your thoughts and achieve a perfect user experience (how is it like advertising? ^_^ ). Of course, you only need to enrich the CSS to achieve more results. For example, to display in bold, you can modify the CSS as follows: . datarowemp
{} {
background-color : #bce3ff ;
font-weight : bold ;
}

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.