PC Review


Reply
Thread Tools Rate Thread

Conditional format of cell

 
 
Rick Beach
Guest
Posts: n/a
 
      16th Feb 2011
I have the below code to format a cell background color to red in my GridView3. This is from my aspx page in source view.

Below is the Gridview with only the column 12 (zero based) listed:

//the first line is show the correct gridview name only
<asp:GridView ID="GridView3" ...
<asp:BoundField DataField="2B Curr Ld" HeaderText="2B Curr Ld" ReadOnly="True" SortExpression="2B Curr Ld" />
</asp:GridView>
Below is the sub created to change the color when the page loads:

<Sub onload>
protected void GridView3_RowDataBound(object sender, GridViewRowEventArgs e)
{
// Check if row is data row, not header, footer etc.
if (e.Row.RowType == DataControlRowType.DataRow)
{
// Get value of twelth column zero based
int CellValue = Convert.ToInt32(e.Row.Cells[12].Text);

// If value is greater of 10, change format
if (CellValue > 10)
{
// Use this syntax to change format of single cell
e.Row.Cells[12].BackColor = System.Drawing.Color.Red;
}
}
}
</Sub>

I am very new to .net and I am not sure if this is in the wrong location, if the programming is actually starting or if the programming itself is incorrect.

I would appreciate any help.

Submitted via EggHeadCafe
Statistics, Probability, Lotteries and Dumb Programmers
http://www.eggheadcafe.com/tutorials...ogrammers.aspx
 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Capture conditional format as cell format Diddy Microsoft Excel Misc 2 23rd Jun 2009 11:01 PM
conditional cell format based on cell in same row, previous column =?Utf-8?B?dGFtaWx1Y2hp?= Microsoft Excel Worksheet Functions 7 3rd May 2006 04:11 PM
Creating a conditional format for a cell based on another cell's v =?Utf-8?B?c3RldmUtbw==?= Microsoft Excel Misc 2 26th Oct 2005 03:51 PM
Conditional format - how can I format a cell based on a DIFFERENT cell's value? Shiperton Henethe Microsoft Excel Discussion 2 19th Nov 2004 05:11 PM
Conditional Format with VBA - Interior Colour of cell based on value from in-cell dropdown Steve Microsoft Excel Programming 5 15th Jun 2004 11:45 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 06:26 AM.