Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Best Way To Do This?
Message
General information
Forum:
ASP.NET
Category:
Coding, syntax and commands
Title:
Best Way To Do This?
Miscellaneous
Thread ID:
01437955
Message ID:
01437955
Views:
119
I have created a user control for an address block. It contains the typcial address info fields on it. It has a List property that can be set to a collection of addresses classes. There is also a combo for selecting the type of address.

I the combo's SelectedIndexChange event has:
private void cboPickList_SelectedIndexChanged(object sender, EventArgs e)
{
    _SelectedAddressKey = cboPickList.SelectedKey;
    _SelectAddress();
}
The _SelectAddress() method has:
private void _SelectAddress()
{
    // PK of the Address Type Key record
    int AddressTypeKey = cboPickList.SelectedKey;

    // Clear out the fields on the control
    txtStreet1.Text = "";
    txtStreet2.Text = "";
    txtCity.Text = "";
    txtState.Text = "";
    txtZipCode.Text = "";

    // Find the Address class in the collection
    foreach (Address address in _Addresses)
    {
        if (address.AddressTypeKey == AddressTypeKey)
        {
            // Clear and rebind the addresss class to the fields on the control
            txtStreet1.DataBindings.Clear();
            txtStreet2.DataBindings.Clear();
            txtCity.DataBindings.Clear();
            txtState.DataBindings.Clear();
            txtZipCode.DataBindings.Clear();

            txtStreet1.DataBindings.Add("Text", address, "Street1");
            txtStreet2.DataBindings.Add("Text", address, "Street2");
            txtCity.DataBindings.Add("Text", address, "City");
            txtState.DataBindings.Add("Text", address, "State");
            txtZipCode.DataBindings.Add("Text", address, "PostalCode");

            break;
        }
    }

    txtStreet1.Focus();
}
This works fine for when the user selects an address type that exists in the collection, but for an address type that does not have an address defined, the fields are blank, but nothing is bound to them, I would now need to write code to create a new address, bind to
it, and store it back to the collection.

Anyone have a better way to do this?

Thanks
Everything makes sense in someone's mind
public class SystemCrasher :ICrashable
In addition, an integer field is not for irrational people
Next
Reply
Map
View

Click here to load this message in the networking platform