Add a class named MyAddress.cs and write the following code:
publicclass MyAddress : SPFieldMultiColumn
{
public MyAddress(SPFieldCollection fields,
string fieldName)
:base(fields, fieldName) { }
public MyAddress(SPFieldCollection fields,
string typeName,
string displayName)
:base(fields, typeName, displayName) { }
public overrideBaseFieldControl FieldRenderingControl
{
get
{
BaseFieldControl ctr =new MyAddressFieldControl();
ctr.FieldName = this.InternalName;
return ctr;
}
}
public overridestring GetFieldValueAsHtml(object value)
{
string HtmlLineBreak =@"<br />";
SPFieldMultiColumnValue mColumnValue =
new SPFieldMultiColumnValue(value.ToString());
string HtmlAddress = mColumnValue [0].ToString() + HtmlLineBreak;
if (!string.IsNullOrEmpty(mcv[1]))
{
HtmlAddress += mcv[1].ToString() + HtmlLineBreak;
}
HtmlAddress += mColumnValue [2].ToString() + ", " + mColumnValue [3] + " " + mColumnValue [4];
return HtmlAddress;
}
}
publicclass MyAddressFieldControl : BaseFieldControl
{
protected overridestring DefaultTemplateName
{
get { return"MyAddressRenderingTemplate"; }
}
protected TextBox txtAddress;
protected TextBox txtCity;
protected TextBox txtState;
protected TextBox txtCountry;
protected TextBox txtZipcode;
protected overridevoid CreateChildControls()
{
base.CreateChildControls();
txtAddress =
(TextBox)this.TemplateContainer.FindControl("txtAddress");
txtCity =
(TextBox)this.TemplateContainer.FindControl("txtCity");
txtState =
(TextBox)this.TemplateContainer.FindControl("txtState");
txtCountry =
(TextBox)this.TemplateContainer.FindControl("txtCountry");
txtZipcode =
(TextBox)this.TemplateContainer.FindControl("txtZipcode");
}
public overrideobject Value
{
get
{
this.EnsureChildControls();
SPFieldMultiColumnValue mColumnValue =new SPFieldMultiColumnValue(5);
mColumnValue [0] = txtAddress.Text;
mColumnValue [1] = txtCity.Text.ToUpper();
mColumnValue [2] = txtState.Text;
mColumnValue [3] = txtCountry.Text;
mColumnValue [4] = txtZipcode.Text;
return mColumnValue;
}
set
{
this.EnsureChildControls();
SPFieldMultiColumnValue mColumnValue =
(SPFieldMultiColumnValue)this.ItemFieldValue;
txtAddress.Text = mColumnValue [0];
txtCity.Text = mColumnValue [1];
txtState.Text = mColumnValue [2];
txtCountry.Text = mColumnValue [3];
txtZipcode.Text = mColumnValue [4];
}
}
}