// Populate child table list
        private void PopulateChildTableListOld(string parentTableName)
        {
            if (String.IsNullOrEmpty(parentTableName))
            {
                return;
            }

            // Populate child table ddl
            IEnumerable <string> childTablesList = Caisis.BOL.BusinessObject.GetDescendantTableNames(parentTableName);

            //ChildTablesRptr.ItemDataBound +=
            //    new RepeaterItemEventHandler(
            //        (o, e) =>
            //        {
            //            CheckBox cb = e.Item.FindControl("cbChildTable") as CheckBox;

            //            if (cb != null)
            //                checkBoxMap[cb.Text] = cb;
            //        });

            ChildTablesRptr.DataSource = childTablesList;
            ChildTablesRptr.DataBind();

            #region old code
            //RegisterJSTableMap(childTablesList);

            //ChildTablesRptr.DataSource = childTablesList;

            //StringBuilder cbScript = new StringBuilder();

            //ChildTablesRptr.ItemDataBound +=
            //    new RepeaterItemEventHandler(
            //        (o, e) =>
            //        {
            //            CheckBox cb = e.Item.FindControl("cbChildTable") as CheckBox;
            //            if (cb != null)
            //            {
            //                string tablename = cb.Text;
            //                string id = cb.UniqueID;

            //                cbScript.AppendFormat("cbmap['{0}'] = '{1}';", tablename, id);
            //                cbScript.AppendLine();
            //                cbScript.AppendFormat("cblist.push('{0}');", id);
            //                cbScript.AppendLine();
            //            }
            //        });

            //ChildTablesRptr.DataBind();

            //Page.ClientScript.RegisterStartupScript(this.GetType(), "checkboxMap", cbScript.ToString(), true);
            #endregion

            if (childTablesList != null && childTablesList.Count() > 0)
            {
                ChildTableSummary.Style["display"] = ";";

                //if (LayoutTypeRBList.Items.FindByValue("List and Grid") == null)
                //    LayoutTypeRBList.Items.Add("List and Grid");
            }
            else
            {
                //ListItem li = new ListItem("List and Grid");
                //if (LayoutTypeRBList.Items.FindByValue("List and Grid") != null)
                //    LayoutTypeRBList.Items.Remove(li);
                ChildTableSummary.Style["display"] = "none;";
            }
        }
        private void PopulateChildTableList(string parentTableName)
        {
            if (!string.IsNullOrEmpty(parentTableName))
            {
                IEnumerable <string> childTablenames = Caisis.BOL.BusinessObject.GetDescendantTableNames(parentTableName);
                List <string>        selectedTables  = GetSchemaChildTableNames();

                Func <string, string> onClick = id => "if (this.checked) $('" + id + "').checked = false;";

                ChildTablesRptr.ItemDataBound +=
                    new RepeaterItemEventHandler(
                        (o, e) =>
                {
                    CheckBox listCheckBox = e.Item.FindControl("childTableListCheckBox") as CheckBox;
                    CheckBox gridCheckBox = e.Item.FindControl("childTableGridCheckBox") as CheckBox;

                    listCheckBox.InputAttributes["onclick"] = onClick(gridCheckBox.ClientID);
                    gridCheckBox.InputAttributes["onclick"] = onClick(listCheckBox.ClientID);

                    // disable list/grid based on relation to parent table
                    string tablename = e.Item.DataItem as string;

                    List <CheckBox> list = new List <CheckBox>();
                    list.Add(listCheckBox);
                    list.Add(gridCheckBox);

                    checkBoxMap[tablename] = list;

                    // if t is one-to-one with parent: disable grid
                    // if t is one-to-many with parent: disable list

                    string primaryKey = Caisis.BOL.BusinessObject.GetPrimaryKeyName(tablename);
                    string parentKey  = Caisis.BOL.BusinessObject.GetPrimaryKeyName(parentTableName);

                    bool precheck = false;

                    if (selectedTables.Contains(tablename))
                    {
                        precheck = true;

                        if (!string.IsNullOrEmpty(SelectedChildTablesLabel.Text))
                        {
                            SelectedChildTablesLabel.Text += ", ";
                        }

                        SelectedChildTablesLabel.Text += tablename;
                    }

                    if (patientsAssigned)
                    {
                        gridCheckBox.Enabled = false;
                        listCheckBox.Enabled = false;

                        if (precheck)
                        {
                            listCheckBox.Checked = primaryKey == parentKey;
                            gridCheckBox.Checked = primaryKey != parentKey;
                        }
                    }
                    else
                    {
                        if (primaryKey == parentKey)
                        {
                            gridCheckBox.Enabled = false;
                            listCheckBox.Enabled = true;

                            if (precheck)
                            {
                                listCheckBox.Checked = true;
                            }
                        }
                        else
                        {
                            gridCheckBox.Enabled = true;
                            listCheckBox.Enabled = false;

                            if (precheck)
                            {
                                gridCheckBox.Checked = true;
                            }
                        }
                    }



                    // TODO: check unchecked parent tables in the list
                });

                ChildTablesRptr.DataSource = childTablenames;
                ChildTablesRptr.DataBind();

                if (childTablenames != null && childTablenames.Count() > 0)
                {
                    ChildTableSummary.Style["display"]    = ";";
                    ChildMenuTextDisplay.Style["display"] = ";";
                }
                else
                {
                    ChildTableSummary.Style["display"]    = "none;";
                    ChildMenuTextDisplay.Style["display"] = "none;";
                }
            }
        }