Hi ,
I am new to programming.. I have one report I need to highlight the column text with red if that value is "Fail" for columns F1results, F2results , F3results ,F4results, F5results. I did added 5 individual if conditions (you can see in below to display this custom color which is working but I know that it's not good programming so that's why I am posting here , is there anyway I can simply it. Thank you so much.
foreach (var data in alldata)
{
var dto = new ReportDto();
dto.Row.Add("Name", data.Name);
dto.Row.Add("Class", data.Class);
dto.Row.Add("F1results", data.F1results);
dto.Row.Add("F2results", data.F2results);
dto.Row.Add("F3results", data.F3results);
dto.Row.Add("F4results", data.F4results);
dto.Row.Add("F5results", data.F5results);
if (result.F1results == "Fail")
{
dto.CustomColors.Add("F1results", "#da3434");
}
if (result.F2results == "Fail")
{
dto.CustomColors.Add("F2results", "#da3434");
}
if (result.F3results == "Fail")
{
dto.CustomColors.Add("F3results", "#da3434");
}
if (result.F4results == "Fail")
{
dto.CustomColors.Add("F4results", "#da3434");
}
if (result.F5results == "Fail")
{
dto.CustomColors.Add("F5results", "#da3434");
}
finalreportdtos.Add(dto);
}
What I have tried:
I have tried like below , But not sure hw can I update colors to text for respective columns here.
foreach (var column in dto.Row.Keys)
{
if(column == "F1results" || column== "F2results" || column== "F3results" || column == "F4results" || column == "F5results")
{
}
}