0
조건부로 셀 값에 따라 서식이 지정된 표가 있습니다. 페이지가로드 될 때 효과적입니다. 그러나 행을 선택하면 모든 행에 대해 첫 번째 조건 (검정색)으로 서식이 지정됩니다. 다음은 조건부 서식의 코드입니다.행 선택 후 Gridview의 조건부 서식이 작동하지 않습니다.
//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;
}
}
}
문제를 일으키는 방법이나 좋은 것입니다 문제를 해결하기 위해 할 수있는 무엇에 어떤 도움.
어떤 방법을 사용하고 있습니까? DataBound? DataBind? RowCreating? 이것을 게시 할 수 있습니까? – Fals
또한 행 선택을 사용할 수 있다고 가정하면 선택한 행에 재정의해야하는 서식 세트가 있습니다. 행 선택 이벤트에서 동일한 조건부 서식을 적용해야합니다. – fnostro
RowCreated 메서드입니다. – cal5barton