Asp. NET essay-Displays the color of the GridView cell by condition

Source: Internet
Author: User

Problem Description:

I was having a problem with a credit card business: When the amount in the credit card was less than 100, the number color was red and the rest was green.

Before, trying to modify the template column and convert it to reapeater control, even with jquery, did not achieve the desired effect, the code chores difficult to understand. By querying the relevant information, see the introduction about DataRowView.

Not too much to introduce here

Front Office Core Code:

<asp:boundfield headertext="ID Number"Datafield="Identitycardnumber"/> <asp:boundfield headertext="Sex"Datafield="Sex"/> <asp:boundfield headertext="Personal credit rating"Datafield="Creditstandard"/> <asp:boundfield headertext="in-card amount"Datafield=" Money"/>

Background Core code:

Gvcarduser.datasource = ds. tables[0];            Gvcarduser.databind ();  for(inti =0; i < GvCardUser.Rows.Count; i++) {DataRowView DGV= ds. tables[0].                Defaultview[i]; stringMoney = convert.tostring (dgv[" Money"]); if(Convert.todouble (Money) < -) {Gvcarduser.rows[i]. cells[5]. ForeColor =System.Drawing.Color.Red; }                Else{gvcarduser.rows[i]. cells[5]. ForeColor =System.Drawing.Color.Green; }            }

This code is bound to the data and is implemented at Page_Load.

DataRowView DGV = ds. Tables[0]. Defaultview[i];

Get user-defined views

Gvcarduser.rows[i]. CELLS[5]. ForeColor = System.Drawing.Color.Red;
Change font Color


Through the above operation, you can achieve the effect, display:

Accumulate experience, record development experience, do more with less

Asp. NET essay-Displays the color of the GridView cell by condition

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.