Coloring DataGrid Cells

Coloring DataGrid Cells

am 29.01.2008 15:15:05 von Anthony Peterson

I'm trying to display the text in cells in red whenever the input is
invalid syntactically or out of the bounds of tolerance checks that
are run on the server. My datagrid doesn't use the row based Editing
system but instead has a save button for the whole datagrid and all
cells are text boxes.

I'm using the following code to finish up processing of my datagrid
(which is dynamically created on each postback) and in that code I
have tried to make these bad data cells red, but the cells stay the
same color. I'm looking for solutions to this problem, if possible.

internal void finishSetup(List fields,
DataTable table)
{
dg.Width = Unit.Pixel(55 * fields.Count);
dg.DataSource = table;
BindData();

foreach (InvalidDatum d in InvalidData.Data)
{
if (d.IsSyntaxProblem)
((TextBox)dg.Items[d.RowIndex].Cells[d.CellIndex].FindContro l(fields[d.CellIndex].fieldName)).ForeColor
= System.Drawing.Color.Red;
else
((TextBox)dg.Items[d.RowIndex].Cells[d.CellIndex].FindContro l(fields[d.CellIndex].fieldName)).ForeColor
= System.Drawing.Color.Purple;
}
}

InvalidData.Data is a static member of that class that is filled
during Tolerance checking with a InvalidDatum object for each case of
bad syntax and data outside its Tolerances (for instance, Ph less than
3)