Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.2k views
in Technique[技术] by (71.8m points)

c# - RDLC dynamically add images to report

I have list of images in remote server, i need to show some of these images in a existing report. I tried by dropping an image control to the rdlc and it works for single image.

But i need to show more than one image, which has no fixed count.

I referred below posts, but none are clear:

C# - Add List of images to report viewer

Insert unknown number of Images to the report at runtime using reportviewer

http://www.c-sharpcorner.com/blogs/6194/display-image-in-rdlc-report-microsoft-report-viewer.aspx%27

I know there might be possible duplicates for this request, please guide me if so.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

I started by adding a table to the existing reports, as in above mentioned post, removed the unnecessary columns, then added an image to the left out cell in the rdlc design. In the image property set the source to "External"

set the source to "External"

Now open the rdlc in xml view, there find the dataset tag, add a new dataset for the new table with images

<DataSet Name="DataSet1">
  <Fields>
    <Field Name="filepath">
      <DataField>track_file_id_pk</DataField>
      <rd:TypeName>System.string</rd:TypeName>
    </Field>
    </Field>
  </Fields>
  <Query>
    <DataSourceName>xxxt</DataSourceName>
    <CommandText>/* Local Query */</CommandText>
  </Query>
  <rd:DataSetInfo>
    <rd:DataSetName>xxx</rd:DataSetName>
    ...
  </rd:DataSetInfo>
</DataSet>

Now adding the images list dataset to the new table as shown below

<Tablix Name="Tablix2">
    ....
    </TablixRowHierarchy>
    <DataSetName>ImgDataSet</DataSetName>

Go back to design view of rdlc, go to image properties, set the "use this image" field

set the "use this image" field

In code behind create Datatable with one column "filepath", add rows with images filepath then add datasource to report below the existing datasource.

DataTable dtable = new DataTable();
DataColumn dcol = new DataColumn("filepath");
dtable.Columns.Add(dcol);

DataRow drow = dtable.NewRow();
string pat = new Uri(Server.MapPath("~/Content/DSC_019.jpg")).AbsoluteUri;
drow["track_file_uuidName"] = pat;
dtable.Rows.Add(drow);
...

ReportViewer1.LocalReport.EnableExternalImages = true;

...
ReportViewer1.LocalReport.DataSources.Clear();
ReportViewer1.LocalReport.DataSources.Add(new ReportDataSource("rptDataSet", objCommonreport.ReportTable));
ReportViewer1.LocalReport.DataSources.Add(new ReportDataSource("DataSet1", dtable));

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...