さまざまな場所の列がハードコーディングされていた古いアプリを使用していますが、新しい場所が追加されたので、物事を動的に入力することにしました。アプリの機能の 1 つは、ステータスが「悪い」と見なされたときに赤いテキストと太字のテキストを表示することでした。これは、TemplateFields で選択された行内のセルから「FindControl()」関数を使用して実行されました。
バインドされたフィールドを使用するようにこれを設定したので、DataBound イベント中にテキストの色やサイズなどを変更するにはどうすればよいでしょうか?
GridView に追加される BoundField
BoundField statusField = new BoundField();
statusField.DataField = "ExceptionStatusCode";
statusField.HeaderText = "Status";
statusField.SortExpression = "ExceptionStatusCode";
this.gvView.Columns.Add(statusField);
GridView の DataBound イベント
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;
}
}
}