I follow the instruction from Microsoft to create a custom address field type. I have 3 address: visiting, postal, and invoicing. So I based on the SPFieldMultiColumnValue to implement. Following is the class of CustomAddress
public class CustomAddress : SPFieldMultiColumn
{
public CustomAddress(SPFieldCollection fields,
string fieldName)
: base(fields, fieldName) { }
public CustomAddress(SPFieldCollection fields,
string typeName,
string displayName)
: base(fields, typeName, displayName) { }
public override BaseFieldControl FieldRenderingControl
{
get
{
BaseFieldControl ctr = new AddressFieldControl();
ctr.FieldName = this.InternalName;
return ctr;
}
}
public override string GetFieldValueAsHtml(object value)
{
string HtmlLineBreak = @"<br />";
SPFieldMultiColumnValue mcv = new SPFieldMultiColumnValue(value.ToString());
string HtmlAddress = "";
for (int i = 0; i < mcv.Count; i++)
{
HtmlAddress += mcv[i].ToString() + HtmlLineBreak;
}
return HtmlAddress;
}
}
I set mvc[0] as Visting address, mvc[ 1] as postal address and mvc [2] as invoicing address. Everything works fine for creating and editing item. However, I have issue with viewing item (DisplayForm.aspx). It just shows the visiting address only. Look like it just get the mvc[0] and ignore mvc[ 1] and mvc[ 2]. Please help!