public class AttachmentAwareSPBoundField : SPBoundField
{
protected override void ChildControlDataBinding(Control childControl, object dataItem,
MemberDescriptor dataFieldPropertyDescriptor)
{
PlaceHolder placeHolder = (PlaceHolder) childControl;
string propertyValueAsHtml = GetPropertyValueAsHtml(dataItem, dataFieldPropertyDescriptor.Name);
if (!string.IsNullOrEmpty(propertyValueAsHtml))
{
bool hasAttachment;
if (bool.TryParse(propertyValueAsHtml, out hasAttachment))
{
if (hasAttachment)
{
Image image = new Image();
image.ImageUrl = "/_layouts/images/attach.gif";
placeHolder.Controls.Add(image);
}
}
else
{
Label label = new Label();
label.Text = SPHttpUtility.NoEncode(propertyValueAsHtml);
placeHolder.Controls.Add(label);
}
}
}
protected override Control GetChildControlInstance()
{
return new PlaceHolder();
}
}