private void initTable_BL() { DataTool dbTool = new DataTool(); DataTable dtAllergy = dbTool.getAllergy(Int32.Parse(Session["PatientID"].ToString())); int rCnt = dtAllergy.Rows.Count; for (int j = 0; j < rCnt; j++) { TableRow r = new TableRow(); for (int i = 0; i < 4; i++) { if (j == rCnt) { break; } DataRow drAllergy = dtAllergy.Rows[j]; TableCell c = new TableCell(); if (c.HasControls()) { c.Controls.Clear(); } HtmlInputCheckBox chk = new HtmlInputCheckBox(); chk.Value = drAllergy["AllergyID"].ToString(); chk.ID = "chkAllergy" + drAllergy["AllergyID"].ToString(); if (Session["mode"] != null) { if (Session["mode"].ToString() == "view") { chk.Disabled = true; } if (!Convert.IsDBNull(drAllergy["PAllergy"])) { chk.Checked = true; } else { chk.Checked = false; } } c.Controls.Add(chk); c.Width = System.Web.UI.WebControls.Unit.Percentage(25); c.Controls.Add(new LiteralControl(" " + drAllergy["AllergyName"].ToString())); r.Cells.Add(c); j++; } tblAll.Rows.Add(r); } }