getting an null value in approved application:
public void Load_FullGrid() { try { DatabaseContext db = new DatabaseContext(); List<GridList> GVList = new List<GridList>(); var _districts = db.Districts.Where(x => x.isActive == true).Select(x => new { Id = x.Id, Name = x.Name }).OrderBy(x => x.Name).ToList(); DataTable _dt = new DataTable(); _dt.Columns.Add(""); _dt.Columns.Add(""); foreach (var _dist in _districts) { _dt.Columns.Add(""); _dt.Columns.Add(""); _dt.Columns.Add(""); _dt.Columns.Add(""); _dt.Columns.Add(""); _dt.Columns.Add(""); _dt.Columns.Add(""); } _dt.Columns.Add(""); _dt.Columns.Add(""); _dt.Columns.Add(""); _dt.Columns.Add(""); _dt.Columns.Add(""); _dt.Columns.Add(""); _dt.Columns.Add(""); int i; i = 2; DataRow dr0 = _dt.NewRow(); foreach (var _dist in _districts) { dr0[i] = _dist.Name; i = i + 7; } dr0[i] = "GRAND TOTAL"; _dt.Rows.Add(dr0); DataRow dr1 = _dt.NewRow(); i = 2; dr1[0] = "PROJECT"; dr1[1] = "ACTIVITY"; foreach (var _dist in _districts) { dr1[i + 0] = "TOTAL APPLICATIONS"; dr1[i + 1] = "APPROVED APPLICATIONS"; dr1[i + 2] = "REJECTED APPLICATIONS"; dr1[i + 3] = "UNDER PROCESS APPLICATIONS"; dr1[i + 4] = "BANK PENDING APPLICATIONS"; dr1[i + 5] = "BRANCH PENDING APPLICATIONS"; dr1[i + 6] = "BRANCH APPROVED APPLICATIONS"; //i = i + 4; i = i + 7; } dr1[i + 0] = "TOTAL APPLICATIONS"; dr1[i + 1] = "APPROVED APPLICATIONS"; dr1[i + 2] = "REJECTED APPLICATIONS"; dr1[i + 3] = "UNDER PROCESS APPLICATIONS"; dr1[i + 4] = "BANK PENDING APPLICATIONS"; dr1[i + 5] = "BRANCH PENDING APPLICATIONS"; dr1[i + 6] = "BRANCH APPROVED APPLICATIONS"; _dt.Rows.Add(dr1); var _activities = (from _activity in db.ProjectActivityMasters join _project in db.Projects on _activity.ProjectId equals _project.Id where _activity.IsActive == true && (_activity.Role == null || _activity.ProjectId == 29) select new { Id = _activity.Id, Activity = _activity.Name, Project = _project.Name, ProjectId = _project.Id }).ToList().OrderBy(x => x.ProjectId).ThenBy(x => x.Activity); foreach (var _act in _activities) { int? a, u, r, t, bank_pending, branch_pending, branch_approved; a = 0; u = 0; r = 0; t = 0; bank_pending = 0; branch_pending = 0; branch_approved = 0; i = 1; DataRow dr = _dt.NewRow(); dr[0] = _act.Project; dr[1] = _act.Activity; foreach (var _dist in _districts) { GridList _gv = new GridList(); _gv.ActId = _act.Id; _gv.ActivityName = _act.Activity; _gv.ProjId = _act.ProjectId; _gv.ProjectName = _act.Project; _gv.DistId = _dist.Id; _gv.DistName = _dist.Name; var _data= (from _applications in db.ApplicationFormBase join _activity in db.ProjectActivityMasters on _applications.ProjectActivityMasterId equals _activity.Id where _activity.Id == _act.Id && _activity.IsActive == true && _applications.DistrictId == _dist.Id select _applications ).ToList(); _gv.Approved = _data.Where(x => x.ApplicationStatus == "approved" && x.NextRole == "0").ToList().Count(); _gv.Pending = _data.Where(x => (x.ApplicationStatus == "pending" && x.NextRole != "0") || (x.ApplicationStatus == "processing" && x.NextRole != "0")).ToList().Count(); _gv.Rejected = _data.Where(x => x.ApplicationStatus == "rejected" && x.NextRole == "0").ToList().Count(); //_gv.Approved = (from _applications in db.ApplicationFormBase // join _activity in db.ProjectActivityMasters // on _applications.ProjectActivityMasterId equals _activity.Id // where _activity.Id == _act.Id && _activity.IsActive == true // && _applications.ApplicationStatus == "approved" && _applications.NextRole == "0" // && _applications.DistrictId == _dist.Id // select _applications // ).ToList().Count(); //_gv.Pending = (from _applications in db.ApplicationFormBase // join _activity in db.ProjectActivityMasters // on _applications.ProjectActivityMasterId equals _activity.Id // where _activity.Id == _act.Id && _activity.IsActive == true // && ( // (_applications.ApplicationStatus == "pending" && _applications.NextRole != "0") // || // (_applications.ApplicationStatus == "processing" && _applications.NextRole != "0") // ) // && _applications.DistrictId == _dist.Id // select _applications // ).ToList().Count(); //_gv.Rejected = (from _applications in db.ApplicationFormBase // join _activity in db.ProjectActivityMasters // on _applications.ProjectActivityMasterId equals _activity.Id // where _activity.Id == _act.Id && _activity.IsActive == true // && _applications.ApplicationStatus == "rejected" && _applications.NextRole == "0" // && _applications.DistrictId == _dist.Id // select _applications // ).ToList().Count(); _gv.Total = _data.ToList().Count(); //_gv.Total = (from _applications in db.ApplicationFormBase // join _activity in db.ProjectActivityMasters // on _applications.ProjectActivityMasterId equals _activity.Id // where _activity.Id == _act.Id && _activity.IsActive == true // && _applications.DistrictId == _dist.Id // select _applications // ).ToList().Count(); _gv.BankPending = _data.Where(x => x.ApplicationStatus == "approved" && x.NextRole == "bank").ToList().Count(); //_gv.BankPending = (from _applications in db.ApplicationFormBase // join _activity in db.ProjectActivityMasters // on _applications.ProjectActivityMasterId equals _activity.Id // where _activity.Id == _act.Id && _activity.IsActive == true // && _applications.ApplicationStatus == "approved" && _applications.NextRole == "bank" // && _applications.DistrictId == _dist.Id // select _applications // ).ToList().Count(); _gv.BankPending = _data.Where(x => x.ApplicationStatus == "approved" && x.NextRole == "branch").ToList().Count(); //_gv.BranchPending = (from _applications in db.ApplicationFormBase // join _activity in db.ProjectActivityMasters // on _applications.ProjectActivityMasterId equals _activity.Id // where _activity.Id == _act.Id && _activity.IsActive == true // && _applications.ApplicationStatus == "approved" && _applications.NextRole == "branch" // && _applications.DistrictId == _dist.Id // select _applications // ).ToList().Count(); ///// _gv.BranchApproved = (from _applications in db.ApplicationFormBase join _activity in db.ProjectActivityMasters on _applications.ProjectActivityMasterId equals _activity.Id join _tran in db.ApplicantRegistrationFormTransactions on _applications.BranchId equals _tran.LoginId where _activity.Id == _act.Id && _activity.IsActive == true && _tran.Action == "approved" && _applications.ApplicationStatus == "approved" && _applications.NextRole == "0" && _applications.DistrictId == _dist.Id select _applications ).ToList().Count(); /// a = a + _gv.Approved + _gv.BankPending + _gv.BranchPending; u = u + _gv.Pending; r = r + _gv.Rejected; t = t + _gv.Total; if (_gv.BankPending == null) _gv.BankPending = 0; if (_gv.BranchPending == null) _gv.BranchPending = 0; if (_gv.BranchApproved == null) _gv.BranchApproved = 0; bank_pending = bank_pending + _gv.BankPending; branch_pending = branch_pending + _gv.BranchPending; branch_approved = branch_approved + _gv.BranchApproved; dr[i + 1] = _gv.Total; dr[i + 2] = _gv.Approved + _gv.BankPending + _gv.BranchPending; dr[i + 3] = _gv.Rejected; dr[i + 4] = _gv.Pending; dr[i + 5] = _gv.BankPending; dr[i + 6] = _gv.BranchPending; dr[i + 7] = _gv.BranchApproved; //dr[i + 8] = bank_pending+ branch_pending+ branch_approved; i = i + 7; GVList.Add(_gv); } dr[i + 1] = t; dr[i + 2] = a; dr[i + 3] = r; dr[i + 4] = u; dr[i + 5] = bank_pending; dr[i + 6] = branch_pending; dr[i + 7] = branch_approved; //dr[i + 8] = bank_pending + branch_pending + branch_approved; _dt.Rows.Add(dr); } if (GridView1.Rows.Count>0) { GridView1.DataSource = null; GridView1.DataBind(); } GridView1.DataSource = _dt; GridView1.DataBind(); } catch (Exception ex) { string s = ex.Message.ToString(); } }