使用reportviewer在运行时将未知数量的图像插入到报表中 [英] Insert unknown number of Images to the report at runtime using reportviewer

查看:153
本文介绍了使用reportviewer在运行时将未知数量的图像插入到报表中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用reportviewer,我想在运行时向报告添加未知数量的图像。
用户应该选择一些图像(在另一个地方),这些图像应该一个接一个地显示在报告中。
您是否知道如何使用reportviewer做到这一点?

I'm using reportviewer and I would like to add an unknown number of images to the report on runtime. The user should select some images (in another place) and those images should be displayed in the report one after the other. Do you have any idea how to do that using reportviewer?

谢谢,
Ofir

thanks, Ofir

推荐答案

我做了以下工作,以显示矩阵中包含未知项目数的图像列表。

I did the following to show a list of images with unknown number of items in a matrix.

首先创建一个只有一个字段的数据集,您可以随意使用,我将其命名为filepath,将数据集的名称命名为DataSet5。您可以更改名称并相应地使用它。

First create a dataset with only one field in it, you can whatever you want , i named it "filepath" and name of dataset to be "DataSet5". You can change the name and use it accordingly.

然后您需要添加一个表,删除不必要的行和列,这样您只剩下1列和行( 1x1)矩阵。在该列中插入图像,立即设置其属性。图像源应该是EXTERNAL。

Then you need to add a table, delete unnecessary rows and columns such that you are left with only 1 column and row (1x1) matrix. Insert an image in that column, set its properties now. Image source should be EXTERNAL.

在报告的aspx.cs文件中,从数据库中获取图像的路径,现在获取这些图像的绝对路径并附加 file:///因为报告需要显示一个文件。我喜欢这样:

In your aspx.cs file for the report, get the paths of the images from the database, now get absolute paths for these and append "file:///" as reports require a file to be shown. I did like this:

string rel_Path = HttpContext.Current.Server.MapPath("~");
if (_articleOrders.Any())
    {
        foreach (ArticleOrder order in _articleOrders)
        {
            if (!string.IsNullOrEmpty(order.ArticleImage))
            {
                if (File.Exists(rel_Path + "\\" + order.ArticleImage))
                {
                    var AIpath = "file:///" + rel_Path + "\\" + order.ArticleImage;
                    articleImagesList.Add(AIpath);
                }
            }
        }
        CreateDatasetForImages(articleImagesList);
    }

然后我将数据添加到数据集中,如下所示:

Then I added data to dataset like below:

private void CreateDatasetForImages(List<string> articleImagesList)
{
    DataTable table = new DataTable();
    table.Columns.Add("filepath", typeof(string));

    foreach (string articleImage in articleImagesList)
    {
        DataRow drow = table.NewRow();
        string pat = articleImage;
        drow["filepath"] = pat;
        table.Rows.Add(drow);
    }
    FlowerBookingReportViewer.LocalReport.DataSources.Add(new ReportDataSource("DataSet5", table));
}

现在再次转到图像属性并将使用此图像设置为[filepath ]因为它是我们数据集中保存图像路径的列的名称。希望它适用于某人!

Now again go to image properties and set "Use This Image" to [filepath] as it the name of the column in our dataset that is holding the path of the image. Hope it works for someone!

这篇关于使用reportviewer在运行时将未知数量的图像插入到报表中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆