I'm trying to create a code where when the user enters five customers into the gridview it gives them an error saying that they should only enter 5 customers; what is happening now is that the user can any amount of customers. I added the error line but it seems I put it the wrong place because the user is still able to add more than 5.
for (int i = 0; i < getCustomer.items.Count; i++)
{
if (getIssue.name[i].idNumber == Customer.name.idNumber)
{
ViewBag.errorMessage = "ID number already exists";
return View(getCustomer);
}
if (getCustomer.items.Count >5)
{
viewBag.errorMessage=Error, You can only enter 5 customers at a time;
}
}
if (name.Count == 0)
{
nametbl.connectionString = ConfigurationManager.ConnectionStrings["CUSTOMERConnectionString"].ConnectionString;
try
{
name = nametbl.getName();
}
catch (Exception ex)
{
LogWrite logWriter = new LogWrite(ex.ToString());
ViewBag.errorMessage = "Unable to Connect to Database. Please see Log file for more Information";
return View(getCustomer);
}
}
You just need to return from command flow like so:
if (getCustomer.items.Count >5)
{
viewBag.errorMessage=Error, You can only enter 5 customers at a time; // <=== AFTER THIS LINE
return View(getCustomer);
}
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments