I have a code that tells user which cells they have left empty or which rows they did not fill out but now users want me to allow them to leave at least two rows EMPTY consecutively.
So I need to change my validation code to work in these scenarios:
- If there is only one empty row, log error then go to the next row.
- If there are two consecutive empty rows, go to next row check if it is null, if it is null log error, if not do the happy dance.
For the below example, my code will acknowledge ROW 3
is null and will log it as an error and go to the next row but it is not skipping the two consecutive empty rows. But I want it to skip and go to the next row.
Row 1 | Filled
Row 2 | Filled
Row 3 |
Row 4 | Filled
Row 5 |
Row 6 |
Row 7 | Filled
foreach (DataRow row in data.Rows)
{
currentRowErrors.Clear();
if (row[0] == DBNull.Value)
{
cnt = cnt + 1;
if (cnt == 2)
{
rowCounter = rowCounter + 2;
}
}
//log errors
if (row[0] == DBNull.Value)
{
if (row[0] == DBNull.Value)
{
model.Errors.Add(new RowErrorModel()
{
Row = rowCounter,
Error = "The name cannot be blank."
});
}
}
}