I'm working with an old app that had hard coded columns for different locations, now that new locations are being added I decided to try and make things populate dynamically. One of the features of the app was displaying red text and bolding text when a status was deemed "bad". This was executed by using the "FindControl()" function from the cells within the selected row with TemplateFields.
Now that I've set this up to use a bound field, how would I go about changing the text color, size, etc. during the DataBound event?
BoundField Being Added To GridView
BoundField statusField = new BoundField();
statusField.DataField = "ExceptionStatusCode";
statusField.HeaderText = "Status";
statusField.SortExpression = "ExceptionStatusCode";
this.gvView.Columns.Add(statusField);
DataBound Event For GridView
protected void gvView_DataBound(object sender, EventArgs e)
{
foreach (GridViewRow row in this.gvView.Rows)
{
//NO LONGER WORKS, NEED TO KNOW HOW TO REPRODUCE
//WHAT IS BELOW FOR BOUND FIELD
Label lblPartStatus = ((Label) row.Cells[StatusColumn].FindControl("lblPartStatus"));
if (lblPartStatus.Text == "BAD")
{
lblPartStatus.ForeColor = System.Drawing.Color.Red;
row.ToolTip = "One or more locations is missing information!";
row.BackColor = System.Drawing.Color.Salmon;
}
}
}