Example #1
0
        protected void btnAdd_Click(object sender, EventArgs e)
        {
            var footer                 = GetFooter();
            var ddlTypeF               = (DropDownList)footer.FindControl("ddlTypeF");
            var txtAttentionLineF      = (TextBox)footer.FindControl("txtAttentionLineF");
            var txtStreetAddressLine1F = (TextBox)footer.FindControl("txtStreetAddressLine1F");
            var txtStreetAddressLine2F = (TextBox)footer.FindControl("txtStreetAddressLine2F");
            var txtCityF               = (TextBox)footer.FindControl("txtCityF");
            var txtStateF              = (TextBox)footer.FindControl("txtStateF");
            var txtZipF                = (TextBox)footer.FindControl("txtZipF");
            var txtCountryF            = (TextBox)footer.FindControl("txtCountryF");

            if (!string.IsNullOrEmpty(txtStreetAddressLine1F.Text))
            {
                var type = AddressTypes.First(x => x.Field == ddlTypeF.SelectedValue).Field;

                AddressItem item = new AddressItem()
                {
                    AddressID    = 0,
                    AddressType  = type,
                    Attention    = txtAttentionLineF.Text,
                    AddressLine1 = txtStreetAddressLine1F.Text,
                    AddressLine2 = txtStreetAddressLine2F.Text,
                    City         = txtCityF.Text,
                    State        = txtStateF.Text,
                    Zip          = txtZipF.Text,
                    Country      = txtCountryF.Text
                };

                CreateAddress?.Invoke(this, new CreateAddressEventArgs()
                {
                    NewItem = item
                });
            }
        }
Example #2
0
        private AddressItem GetUpdateItem()
        {
            var repeaterItem = rptAddressManager.Items[EditItemIndex];

            var ddlType               = ((DropDownList)repeaterItem.FindControl("ddlType"));
            var txtAttentionLine      = ((TextBox)repeaterItem.FindControl("txtAttentionLine"));
            var txtStreetAddressLine1 = ((TextBox)repeaterItem.FindControl("txtStreetAddressLine1"));
            var txtStreetAddressLine2 = ((TextBox)repeaterItem.FindControl("txtStreetAddressLine2"));
            var txtCity               = ((TextBox)repeaterItem.FindControl("txtCity"));
            var txtState              = ((TextBox)repeaterItem.FindControl("txtState"));
            var txtZip       = ((TextBox)repeaterItem.FindControl("txtZip"));
            var txtCountry   = ((TextBox)repeaterItem.FindControl("txtCountry"));
            var hidAddressID = (HiddenField)repeaterItem.FindControl("hidAddressID");

            var addrType = AddressTypes.First(x => x.Field == ddlType.SelectedValue).Field;

            var result = new AddressItem()
            {
                AddressID    = int.Parse(hidAddressID.Value),
                AddressType  = addrType,
                Attention    = txtAttentionLine.Text,
                AddressLine1 = txtStreetAddressLine1.Text,
                AddressLine2 = txtStreetAddressLine2.Text,
                City         = txtCity.Text,
                State        = txtState.Text,
                Zip          = txtZip.Text,
                Country      = txtCountry.Text
            };

            return(result);
        }
Example #3
0
        private void BeginEdit()
        {
            if (EditItemIndex > -1)
            {
                RepeaterItem item = rptAddressManager.Items[EditItemIndex];
                HtmlTableRow tr   = (HtmlTableRow)item.FindControl("trItem");
                tr.Attributes.Add("class", "editing");
                SetVisibility(item, "lblAttentionLine", false);
                SetVisibility(item, "txtAttentionLine", true);
                SetVisibility(item, "lblStreetAddressLine1", false);
                SetVisibility(item, "txtStreetAddressLine1", true);
                SetVisibility(item, "lblStreetAddressLine2", false);
                SetVisibility(item, "txtStreetAddressLine2", true);
                SetVisibility(item, "lblCity", false);
                SetVisibility(item, "txtCity", true);
                SetVisibility(item, "lblState", false);
                SetVisibility(item, "txtState", true);
                SetVisibility(item, "lblZip", false);
                SetVisibility(item, "txtZip", true);
                SetVisibility(item, "lblCountry", false);
                SetVisibility(item, "txtCountry", true);
                SetVisibility(item, "btnEdit", false);
                SetVisibility(item, "btnDelete", false);
                SetVisibility(item, "btnUpdate", true);
                SetVisibility(item, "btnCancel", true);

                IList <AddressType> dataSource = FilteredAddressTypes().ToList();

                //we need to add this item's address type back in
                AddressItem dataItem = Items[item.ItemIndex];
                dataSource.Add(new AddressType()
                {
                    Field = dataItem.AddressType, Name = GetAddressTypeName(dataItem.AddressType)
                });

                Label        lblType = (Label)item.FindControl("lblType");
                DropDownList ddlType = (DropDownList)item.FindControl("ddlType");
                ddlType.DataSource = dataSource.OrderBy(x => x.Name);
                ddlType.DataBind();
                ddlType.SelectedValue = ddlType.Items.FindByText(lblType.Text).Value;

                lblType.Visible = false;
                ddlType.Visible = true;
            }
        }