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