我有一个SPlist(ina发布网站),其中包含以下字段:“Title”,“MessageContent”,“ID”,“附件”。 在我的ListView控件中,我在格式化表中显示此SPlist的内容。
在listview中,我已成功将属性绑定到子控件,并且我正确地呈现数据。我需要以下逻辑:如果此项目有附件,则将回形针图像显示为附件的超链接。图像位于此sharepoint站点的图像库中。 你会怎么做? 注意(我没有使用每个循环来显示内容。我使用现有的控制功能并绑定每个属性(来自datatable的SPlist字段))。 提前谢谢。
代码: ASCX
<ItemTemplate>
<td class="tdItemMessage">
<table class="tableItemMessage">
<tr>
<td class="tdMessageConent tdMessageCreated">
<div class="divMessageCreated">
<asp:Label ID="lblMessageDate" runat="server" OnDataBinding="lblMessageDate_DataBinding" Text='<%# Bind("Created")%>'></asp:Label></div>
</td>
<td class="tdMessageConent">
<div class="divMessageTitle"><%# Eval("Title")%> </div>
</td>
</tr>
<tr>
<td class="tdMessageConent tdMessageCreated">
</td>
<td class="tdMessageConent">
<div class="divMessageShortMessage"><asp:Label ID="lblShortMessage" runat="server" OnDataBinding="txtBox1_DataBound" Text='<%# Bind("MessageContent")%>' ToolTip='<%# Bind("ID")%>'></asp:Label></div>
</td>
<td class="attachment">
<div id="attachPic" class="msgAttach" runat="server" dir="rtl">
**** I WANT TO INSERT PAPERCLIP IMAGE WITH LINK TO ATTACHMENT (if exists) HERE ****
</div>
</td>
</tr>
</table>
</td>
</ItemTemplate>
答案 0 :(得分:0)
我自己挖出来了:
Private Sub ListViewMsg_ItemDataBound(sender As Object, e As ListViewItemEventArgs) Handles ListViewMsg.ItemDataBound
Dim list As SPList = SPContext.Current.Web.Lists(ListId)
Dim view As SPView = list.Views(ViewId)
Dim lItems As SPListItemCollection = list.GetItems(view)
Dim lItem As SPListItem = lItems.GetItemById(CType(e.Item.FindControl("lblShortMessage"), Label).ToolTip) <<----[NOTE] I bounded the ID column from the list to this property.
If lItem.Attachments.Count > 0 Then
For indx As Integer = 0 To lItem.Attachments.Count - 1
Try
Dim itemURL As String = lItem.Attachments.UrlPrefix & lItem.Attachments(0)
CType(e.Item.FindControl("attachPic"), HtmlControls.HtmlGenericControl).InnerHtml = "<a href=" & itemURL & "><img width=14 height=24 src=http://Site_Collection_Name/sites/devplayground/PublishingImages/PaperClip.gif /></a>"
Catch ex As Exception
MyUtilities.Alert(Me, ex.Message)
End Try
Next
End If
End Sub