Coloring DataGrid Cells

A

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<ScoresheetField> 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].FindControl(fields[d.CellIndex].fieldName)).ForeColor
= System.Drawing.Color.Red;
else
((TextBox)dg.Items[d.RowIndex].Cells[d.CellIndex].FindControl(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)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,070
Latest member
BiogenixGummies

Latest Threads

Top