Home
Our Work
Services
Small Business Intranet
Samples
Training
SharePoint
Hosting
    

dbWeb > Blogs > Brandt Fuchs > Posts > Displaying Attachments in Multiple Item Xslt Data View Web Part

Displaying Attachments in Multiple Item Xslt Data View Web Part
So I had posted an item previously about displaying attachments in a data view web part.  My previous post only works when using a single item view. When working with a multiple item view some modifications to the code are needed.
 
At first I tried this code
 
<SharePoint:AttachmentsField ControlMode="Display" ItemId="{@ID}" EnableViewState="true" FieldName="Attachments" runat="server"/>
 
I though that adding the ItemID attribute would be sufficient, however this proved not to be the case.  The issue I experienced is that this code works in a single item view, but in a multiple item view it selects first item's ID as all item's 'ItemID' attribute on the SharePoint:AttachmentsField control.
 
The result is that if the first item has an attachment, that attachment is displayed for all items.  Likewise if the first item has no attachments, all items display no attachment.

It is obvious to me that the SharePoint:AttachmentField control is not receiving the correct ID for each item, but rather all are receiving the first item's ID.  I can't tell why that is though.

I managed to figure this one out, although I must admit the solution supprised me.  What I did was add the following code right before my SharePoint:AttachmentField control

<SharePoint:AttachmentButton ControlMode="Edit" Enabled="true" ItemId="{@ID}" runat="server" Visible="false"/>

So the code that displays attachments on a multiple item view is as follows.

<SharePoint:AttachmentButton ControlMode="Edit" Enabled="true" ItemId="{@ID}" runat="server" Visible="false"/><SharePoint:AttachmentsField ControlMode="Display" ItemId="{@ID}" EnableViewState="true" FieldName="Attachments" runat="server"/>

Comments

There are no comments yet for this post.