我的SSRS报告从报表服务器上的客户编号特定文件夹中加载每个客户的徽标图像。
我写了一个表达式,根据客户编号形成我的图像URL。
..."http://localhost/images/" + iCustomerNumber.ToString() + "/logo.gif"
我能够正常工作,但我遇到的问题是,当某个特定客户没有图像时,我的报告会显示一个红色X标记代替徽标。在这种情况下,我希望隐藏图像控件本身。有什么想法????
另一个脏解决方案是确保每个客户特定文件夹都有指定的图像!即使客户没有徽标,我也会在尺寸上放置一个大小正方形像素的blank.gif或spacer.gif!。
答案 0 :(得分:5)
您可以尝试添加一些自定义代码,并在Image.Value属性中使用此代码,以便在未找到图像时加载默认图像:
Public Function GetImage(ByRef CustomerNumber As String) As String
' Customer image
Dim ImageCustomerURL As String
ImageCustomerURL = "http://localhost/images/" + CustomerNumber + "/logo.gif"
' Default Image if customer image does not exist
Dim ImageDefaultURL As String
ImageDefaultURL = "http://localhost/images/default.gif"
' Create a web request to see if customer image exists
Dim m_Req As System.Net.HttpWebRequest = System.Net.HttpWebRequest.Create(ImageCustomerURL)
Try
Dim HttpWResp As System.Net.HttpWebResponse = CType(m_Req.GetResponse(), System.Net.HttpWebResponse)
If HttpWResp.StatusCode = System.Net.HttpStatusCode.OK
Return ImageCustomerURL
Else
Return ImageDefaultURL
End If
Catch ex As System.Net.WebException
If ex.Status = System.Net.WebExceptionStatus.ProtocolError Then
Return ImageDefaultURL
End If
End Try
Return ImageDefaultURL
End Function
然后您的Image.Value属性表达式为:
=Code.GetImage(iCustomerNumber.ToString())
编辑:设置Visibility.Hidden属性而不是使用默认图像
嗯,我认为拥有一个默认图片而不是一个空白区域可能会更好,但它确实是同一个想法:
Public Function HideImage(ByRef CustomerNumber As String) As Boolean
' Customer image
Dim ImageCustomerURL As String
ImageCustomerURL = "http://localhost/images/" + CustomerNumber + "/logo.gif"
' Create a web request to see if customer image exists
Dim m_Req As System.Net.HttpWebRequest = System.Net.HttpWebRequest.Create(ImageCustomerURL)
Try
Dim HttpWResp As System.Net.HttpWebResponse = CType(m_Req.GetResponse(), System.Net.HttpWebResponse)
If HttpWResp.StatusCode = System.Net.HttpStatusCode.OK
Return False
Else
Return True
End If
Catch ex As System.Net.WebException
If ex.Status = System.Net.WebExceptionStatus.ProtocolError Then
Return True
End If
End Try
Return True
End Function
然后您的Visibility.Hidden属性表达式为:
=Code.HideImage(iCustomerNumber.ToString())