In WebGrid.NET the ForeColor can be changed programmatically in InitializeRow event handler.
In this topic, you will learn how to programmatically change the ForeColor of all odd rows in WebGrid.
To change the ForeColor of all odd rows in WebGrid
- 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) { int rowPosition = e.Row.Position; int rowIndexSelection = rowPosition%2; if(rowIndexSelection == 0) { e.Row.Style.ForeColor = Color.Red; } }
- Compile and run the Project.