Intersoft WebGrid Documentation
How-to: Change the ForeColor of a cell based on a specific condition
See Also Send comments on this topic.

Glossary Item Box

In WebGrid.NET the ForeColor can be changed programmatically based on specific conditions.

In this topic, you will learn how to programmatically change the ForeColor of all rows that have UK as the Country.

To change the ForeColor of all rows that have UK as the Country

  1. Drag ASP.NET button to your WebForm.
  2. On InitializeRow event handler, put the following code:

    C# Copy ImageCopy Code
    private void WebGrid1_InitializeRow(object sender, ISNet.WebUI.WebGrid.RowEventArgs e)
    {
       string country = e.Row.Cells.GetNamedItem("Country").Text;
                            
       if(country == "UK")
       {
         e.Row.Style.ForeColor = Color.Red;
       }
    }
    

  3. Compile and run the Project.

See Also

©2012 Intersoft Solutions Corp. All Rights Reserved.