SharePoint - how to show the sign of attach in SPGridView

Asked By Bookworm on 31-May-12 05:39 AM
Hi,
i need to show up in a Sharepoint grid view the sign shows there are attached files

thnx in advance
Jitendra Faye replied to Bookworm on 31-May-12 05:44 AM
Refer this link-

http://sharepoint.stackexchange.com/questions/23919/attach-document-from-sharepoint-list-to-gridview



Hope this will help you.

Somesh Yadav replied to Bookworm on 31-May-12 05:51 AM
create a new type of BoundField class. 

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();
  }
}

Now in the place of bound field you can place this 

<MyControls:AttachmentAwareSPBoundField DataField="Attachments" HeaderText="" SortExpression="Attachments" HeaderImageUrl="images/attach.gif"/>


http://sharepoint.stackexchange.com/questions/23919/attach-document-from-sharepoint-list-to-gridview 
http://stackoverflow.com/questions/8242819/attach-sharepoint-2010-list-attachment-to-gridview 

Regards