我有一个报告,我想根据服务组使用外部图像显示。有3个服务组,每个服务组都有自己的标题(标题会相应更改)...问题是,我收到错误:
本地报告处理期间发生错误。
报告'CustQuote'包含外部图像。尚未为此报告设置EnableExternalImages属性。
我在代码和reportviewer上都将属性设置为true,但仍然出现错误....
以下是我在代码中加载图片所做的工作:
private void PopulateImage()
{
try
{
cn = new SqlConnection(GetConnectionString());
SqlCommand myCmd = new SqlCommand("SELECT * FROM [Chargeables_CustQuote] WHERE ID = 8", cn);
cn.Open();
SqlDataReader myReader = myCmd.ExecuteReader();
if (myReader.HasRows)
{
while (myReader.Read())
{
string serv = myReader["ServiceGroup"].ToString();
if (myReader["ServiceGroup"].ToString() == "BCX")
{
ReportParameter paramLogo = new ReportParameter();
paramLogo.Name = "Path";
paramLogo.Values.Add(Server.MapPath("~\\Images\\SOSLetterhead.png"));
rtpViewer.LocalReport.SetParameters(paramLogo);
rtpViewer.LocalReport.EnableExternalImages = true;
rtpViewer.LocalReport.Refresh();
}
}
}
cn.Close();
myReader.Close();
}
catch (System.Data.SqlClient.SqlException ex)
{
string msg = "Select Error:";
msg += ex.Message;
throw new Exception(msg);
}
}
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
runRptViewer();
PopulateImage();
}
}
这是我的报告查看器的样子:
<div>
<rsweb:ReportViewer ID="rtpViewer" runat="server" Font-Names="Verdana" Font-Size="8pt" WaitMessageFont-Names="Verdana" WaitMessageFont-Size="14pt" Width="952px" Height="807px"
EnableExternalImages = “真” &GT;
<asp:ObjectDataSource ID="ObjectDataSource3" runat="server" SelectMethod="GetData" TypeName="SOSDataSetTableAdapters.VCustomerbaseTableAdapter"></asp:ObjectDataSource>
<asp:ObjectDataSource ID="ObjectDataSource2" runat="server" SelectMethod="GetData" TypeName="SOSDataSetTableAdapters.Chargeables_ItemsTableAdapter"></asp:ObjectDataSource>
<asp:ObjectDataSource ID="ObjectDataSource1" runat="server" SelectMethod="GetData" TypeName="SOSDataSetTableAdapters.Chargeables_CustQuoteTableAdapter"></asp:ObjectDataSource>
</div>
对于rdlc报告中的image属性,source已设置为External
,Value已设置为=Parameters!Path.Value
(这是我创建的参数)。该参数使用DataType
文本制作,名称为Path...
答案 0 :(得分:1)
SetParameters
只需ReportParameterCollection
ReportParameter
。
它应该是这样的(未经测试):
ReportParameterCollection params = new ReportParameterCollection();
params.Add(new ReportParameter("Path", Server.MapPath("~\\Images\\SOSLetterhead.png")));
rtpViewer.LocalReport.SetParameters(params);