If you are using the .NET MailAddress class, you can create your own class by inheriting from MailAddress, recreating the constructors you will need and overriding the ToString() method to return DisplayName instead of displayName . The just using DataTextField="Value" should work. Like this:
public class MyMailAddress : MailAddress
{
public MyMailAddress(string emailAddress, string displayName) : base(emailAddress, displayName)
{
}
public override string ToString()
{
return base.DisplayName;
}
}
If you control the code to the class MailAddress, you can override the default ToString() implementation in the class and have it return the DisplayName property, the you can simply set DisplayTextField="Value" like so:
public class MailAddress
{
public MailAddress(string emailAddress, string displayName)
{
_DisplayName = displayName;
_EmailAddress = emailAddress;
}
public MailAddress()
{
_DisplayName = "";
_EmailAddress = "";
}
private string _DisplayName;
public string DisplayName
{
get { return _DisplayName; }
set { _DisplayName = value; }
}
private string _EmailAddress;
public string EmailAddress
{
get { return _EmailAddress; }
set { _EmailAddress = value; }
}
public override string ToString()
{
return DisplayName;
}
}