Currently I'm working on a grid that had some interesting logic. The logic within it currently was put in place to keep from showing duplicate data in a row.
By that, I mean this. I have a grid with multiple columns (10). Currently, a process is set up in the HtmlDataCellPrepared method to check to see if the value of the cell is equal to a session variable. If it is, then leave it blank. Below is the code to show what happens.
settings.HtmlDataCellPrepared = (sender, e) =>
{
if (e.DataColumn.FieldName == "ProgramArea")
{
if (HttpContext.Current.Session["QR_ProgramArea"] != null &&
HttpContext.Current.Session["QR_ProgramArea"].ToString() == e.CellValue.ToString())
e.Cell.Text = " ";
HttpContext.Current.Session["QR_ProgramArea"] = e.CellValue.ToString();
}
My goal is to replace this session variable due that there are times that nothing at all is populated within the column. I need to compare the current value versus the row before. Any help would be appreciated.
So I figured out a solution after a bit more research. The easiest way to eliminate the Session variables would be to look at the previous row's data to see if the same value exists.
settings.HtmlDataCellPrepared = (sender, e) =>
{
var grid = sender as MVCxGridView;
if (e.DataColumn.FieldName == "ProgramArea")
{
if (e.VisibleIndex - 1 >= 0)
{
var previousRow = grid.GetDataRow(e.VisibleIndex - 1);
if (e.CellValue.ToString() == previousRow["ProgramArea"].ToString())
e.Cell.Text = " ";
}
}
Naturally you skip the 1st row, but after that, look at each row and see if the previous row had the same data.