private void LoadCountySupervisorDistricts()
        {
            CountySupervisorsTableBody.Controls.Clear();
            var districts = CountySupervisors
                            .GetCountySupervisorsDistrictsByCountyCode(StateCode, CountyCode).Rows
                            .OfType <DataRow>().OrderBy(r => r.CountySupervisorsCode()).ToList();

            foreach (var d in districts)
            {
                var tr = new TableRow();
                tr.AddTo(CountySupervisorsTableBody);
                new TableCell().AddTo(tr, "delete").Controls.Add(new HtmlInputCheckBox
                {
                    Disabled = d.LocalKey() != null
                });
                new TableCell().AddTo(tr, "exists").Controls.Add(new HtmlInputCheckBox
                {
                    Disabled = true,
                    Checked  = d.LocalKey() != null
                });
                new TableCell().AddTo(tr, "create").Controls.Add(new HtmlInputCheckBox
                {
                    Disabled = d.LocalKey() != null
                });
                new TableCell().AddTo(tr, "code").Controls.Add(new HtmlInputText
                {
                    Value    = d.CountySupervisorsCode(),
                    Disabled = d.LocalKey() != null
                });
                new TableCell().AddTo(tr, "in-shapefile").Controls.Add(new HtmlInputCheckBox
                {
                    Checked = d.IsInShapefile()
                });
                new TableCell().AddTo(tr, "name").Controls.Add(new HtmlInputText
                {
                    Value = d.Name()
                });
            }
            BulkAddCountySupervisors.Disabled = districts.Count > 0;
        }
        private void PopulateCountySupervisorsDistricts(DropDownList dropDownList, string doNotDisable = null,
                                                        string selected = null)
        {
            if (selected == null)
            {
                selected = doNotDisable;
            }
            var districtsTable =
                CountySupervisors.GetCountySupervisorsDistrictsByCountyCode(StateCode, CountyCode)
                .Rows.Cast <DataRow>().ToArray();

            var districtItems = new List <SimpleListItem>
            {
                new SimpleListItem {
                    Text = "<none>", Value = Empty
                },
                districtsTable
                .Select(r => new SimpleListItem {
                    Text = r.Name(), Value = r.CountySupervisorsCode()
                })
                .ToArray()
            };

            Utility.PopulateFromList(dropDownList, districtItems, selected);

            // apply disabling
            foreach (var item in dropDownList.Items.OfType <ListItem>())
            {
                if (item.Value != doNotDisable)
                {
                    var matchingRow =
                        districtsTable.FirstOrDefault(r => r.CountySupervisorsCode() == item.Value);
                    if (!IsNullOrWhiteSpace(matchingRow?.LocalKey()))
                    {
                        item.Attributes.Add("disabled", "disabled");
                    }
                }
            }
        }