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
- Drag ASP.NET button to your WebForm.
- On InitializeRow event handler, put the following code:
C# Copy 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; } }
- Compile and run the Project.