セル値に基づいて条件付きでフォーマットされるグリッドビューがあります。ページが読み込まれるとうまく機能しますが、行を選択すると、すべての行に対して最初に指定された条件 (黒) に合わせてフォーマットされます。条件付き書式のコードは次のとおりです。
//Conditionally formats the gridview to show banner colors
protected void EmployeeAchievementsGV_RowCreated(object sender, GridViewRowEventArgs e)
{
//Black Banner
if (e.Row.RowType == DataControlRowType.DataRow)
{
int CellValue = Convert.ToInt32(DataBinder.Eval(e.Row.DataItem, "TotalAchievementsEarned"));
if (CellValue >= 0 && CellValue < 12)
{
e.Row.BackColor = Color.Black;
e.Row.Cells[0].ForeColor = Color.White;
e.Row.Cells[1].ForeColor = Color.White;
e.Row.Cells[2].ForeColor = Color.White;
}
}
//Yellow Banner
if (e.Row.RowType == DataControlRowType.DataRow)
{
int CellValue = Convert.ToInt32(DataBinder.Eval(e.Row.DataItem, "TotalAchievementsEarned"));
if (CellValue >= 12 && CellValue < 24)
{
e.Row.BackColor = Color.Yellow;
e.Row.Cells[0].ForeColor = Color.Black;
e.Row.Cells[1].ForeColor = Color.Black;
e.Row.Cells[2].ForeColor = Color.Black;
}
}
//Blue Banner
if (e.Row.RowType == DataControlRowType.DataRow)
{
int CellValue = Convert.ToInt32(DataBinder.Eval(e.Row.DataItem, "TotalAchievementsEarned"));
if (CellValue >= 24 && CellValue < 36)
{
e.Row.BackColor = Color.DodgerBlue;
e.Row.Cells[0].ForeColor = Color.White;
e.Row.Cells[1].ForeColor = Color.White;
e.Row.Cells[2].ForeColor = Color.White;
}
}
//Orange Banner
if (e.Row.RowType == DataControlRowType.DataRow)
{
int CellValue = Convert.ToInt32(DataBinder.Eval(e.Row.DataItem, "TotalAchievementsEarned"));
if (CellValue >= 36 && CellValue < 48)
{
e.Row.BackColor = Color.Orange;
e.Row.Cells[0].ForeColor = Color.Black;
e.Row.Cells[1].ForeColor = Color.Black;
e.Row.Cells[2].ForeColor = Color.Black;
}
}
//Pink Banner
if (e.Row.RowType == DataControlRowType.DataRow)
{
int CellValue = Convert.ToInt32(DataBinder.Eval(e.Row.DataItem, "TotalAchievementsEarned"));
if (CellValue >= 48)
{
e.Row.BackColor = Color.HotPink;
e.Row.Cells[0].ForeColor = Color.Black;
e.Row.Cells[1].ForeColor = Color.Black;
e.Row.Cells[2].ForeColor = Color.Black;
}
}
}
問題の原因や問題の解決方法についてのヘルプは素晴らしいでしょう.