Register   |  Login
You are hereArticles
 Article Details
Highlighting cells of a datagrid

This article briefly explains how to highlight the particular cell in a datagrid based on the cell value.

This article briefly explains how to highlight the particular cell in a datagrid based on the cell value.
Here, in the following example a template column is used inside the datagrid.
Before datagrid control writes the cell value, it calls the public function GetColor and sets back ground color for the label.

 

 
<asp:TemplateColumnHeaderText="New Label%">
 <ItemTemplate>
      <asp:Labelrunat="server"BackColor='<%# GetColor(DataBinder.Eval(Container, "DataItem.ColName")) %>'Text='<%# DataBinder.Eval(Container, "DataItem.ColName
") %>'>
      </asp:Label>
 </ItemTemplate>
</asp:TemplateColumn>
 
public System.Drawing.Color GetColor(object result)
            {
                  if(result!=DBNull.Value)
                  {
                        if(System.Convert.ToInt32(result)<=50)
                        {
                              return System.Drawing.Color.LightGreen;// "green";
                        }
                        else                    {
                              return System.Drawing.Color.LightPink;//"red";
                        }
                  }
                  else
                  {
                        return System.Drawing.Color.White;//"white";
                  }
            }
 

If the cell value is less than or equal to 50, the back ground color would be green. If the value is greater than 50, the back ground color would be in red.


Written By: thysuper
Date Posted: 1/1/2009
Number of Views: 288


Comments
lu juan Says:
4/5/2011 5:25:08 PM

My favorite part of the suite is Microsoft Office 2010 . You can use it like a fancy clipboard, but Office 2010 is much more powerful and useful.So, I'm forced to pay for an upgrade to Microsoft Office that I did not want.For the price, you can't go wrong with Outlook 2010 Home & Student. And, I may or may not be able to use the Product Key on the package I purchased to activate only Word, Excel, Microsoft outlook 2010PowerPoint and OneNote, the programs I thought I was buying. The only answer was to go to MS Office, or have everyone else in the world switch to Office 2007 .The instructions on the Microsoft website for activating Office imply that the full Microsoft Office 2007 Professional suite is the only version eligible for proper licensing.


You must be logged in to submit a comment.

Return