Shovan Saha

Shovan Saha

  • NA
  • 321
  • 92.6k

Please check my code

Sep 17 2017 10:54 AM
If any of row.Cells[2] or [3] is null then how can I edit this? :
 
if (_product.Where(x => x.Type.ToLower() == row.Cells[0].Value.ToString().ToLower()).Any())
{
string TotalQty = (Convert.ToInt32(_product.Where(x => x.Type.ToLower() == row.Cells[0].Value.ToString().ToLower()).Select(x => x.TotalQty).FirstOrDefault()) + Convert.ToInt32(row.Cells[3].Value.ToString())).ToString();
string TotalPrice = (Convert.ToInt32(_product.Where(x => x.Type.ToLower() == row.Cells[0].Value.ToString().ToLower()).Select(x => x.TotalPrice).FirstOrDefault()) + Convert.ToInt32(row.Cells[2].Value.ToString())).ToString();
_product.Where(x => x.Type.ToLower() == row.Cells[0].Value.ToString().ToLower()).ToList().ForEach(x => { x.TotalQty = TotalQty; x.TotalPrice = TotalPrice; });
}
 

Answers (2)