Your DataBound control often shows data not directly found in the Entity class.
It might come from data in the Web Form, such as in a textbox, the query string or the Session collection.
It might come from the Entity but be a combination of several string-type DataFields
carefully formatted together using HTML. It could be a mixture of these, and much more.
Use the ResolveDataField event on the BLDPageManager control to address these issues.
Start by creating its event handler method and defining a unique name for a DataField.
Your job is to return a DataFieldDescriptor class that returns the desired value from its
GetValue() method, based on the DataField supplied.
When the ResolveDataField event is called, it passes each DataField name not located in the Entity class.
This technique has been used in our Interactive UI Demo
to create a tooltip that combines
Supplier.City, Supplier.Region, and Supplier.Country DataFields. Here is the relevant code.
The CustomDataFieldDescriptor class is a DataFieldDescriptor that calls its own event handler
to get the content from the page to return in its GetValue() method. In this case, it uses the CompanyLocationGetContent() method.
protected void ResolveDataField(object sender, PeterBlum.DES.BLD.ResolveDataFieldEventArgs args)
{
switch (args.DataField)
{
case "CompanyLocation":
CustomDataFieldDescriptor vDFD = new CustomDataFieldDescriptor(
"CompanyLocation", typeof(string), CompanyLocationGetContent);
args.DataFieldDescriptor = vDFD;
break;
}
}
public object CompanyLocationGetContent(BaseCustomDataFieldDescriptor sender, object entity, object host)
{
PeterBlum.WithDataAnnotations.Supplier vSupplier = ((PeterBlum.WithDataAnnotations.Product)entity).Supplier;
if (vSupplier == null)
return null;
StringBuilder vSB = new StringBuilder();
if (!String.IsNullOrEmpty(vSupplier.City))
{
vSB.Append(vSupplier.City);
vSB.Append(", ");
}
if (!String.IsNullOrEmpty(vSupplier.Region))
{
vSB.Append(vSupplier.Region);
vSB.Append(" ");
}
if (!String.IsNullOrEmpty(vSupplier.Country) &&
(String.Compare(vSupplier.Country, "United States", StringComparison.CurrentCultureIgnoreCase) != 0))
{
vSB.Append(vSupplier.Country);
}
return vSB.ToString();
}
<des:BLDPageManager ID="BLDPageManager1" runat="server" AutoLoadForeignKeys="true"
OnResolveDataField="ResolveDataField">
<Adapters>
<des:BLDListViewAdapter DataBoundControlID="BLDListView1"
ConnectedToControlID="BLDFormView1"
SupportsEditActions="false" SupportsInsertActions="false"
AllowForeignKeyNavigation="false" />
<des:BLDFormViewAdapter DataBoundControlID="BLDFormView1"
ConnectedToControlID="BLDListView1"
SupportsInsertActions="false" SupportsEditActions="false" />
</Adapters>
</des:BLDPageManager>