private void DetailsView2Databinding() { string ProjectID = Request.Params["ProjectID"]; if (!string.IsNullOrEmpty(ProjectID)) { Project.ProjectDataTable p = projectBLL.GetDataByID(ProjectID); DetailsView2.DataSource = p; GenerateJobSheet(p); var fieldCount = DetailsView2.Fields.Count; // Assumes there is one field after these four fields var FieldColumns = new Dictionary <string, int>(); FieldColumns.Add("AddedAt", fieldCount - 5); FieldColumns.Add("JobSheetSubmitted", fieldCount - 4); FieldColumns.Add("FeeProposalSubmitted", fieldCount - 3); FieldColumns.Add("AcceptanceOfServiceSubmitted", fieldCount - 2); foreach (KeyValuePair <string, int> item in FieldColumns) { DetailsView2.Fields[item.Value].Visible = p.Rows[0][item.Key] != DBNull.Value; } DetailsView2.DataBind(); HasJobSheet = p.Rows[0]["JobSheetSubmitted"] != DBNull.Value; JobSheetMandatoryMarker.Visible = !HasJobSheet; } DetailsView2.CssClass = DetailsView2.CurrentMode.ToString().ToLower(); }