Picturebox contents from second web service datasource

1 Answer 183 Views
PictureBox
Neil N
Top achievements
Rank 2
Iron
Iron
Veteran
Neil N asked on 05 Apr 2023, 03:40 PM
I have a report with two webservice data sources - webServiceDataSource1 and webServiceDataSource2.  In the Report Designer, how do I get a picturebox control to get the base64 string (which may be null) from the webServiceDataSource2.imageBase64 field?

1 Answer, 1 is accepted

Sort by
0
Dimitar
Telerik team
answered on 10 Apr 2023, 07:24 AM

Hello Neil,

If I understand correctly, the PictureBox in question is used within a data item whose DataSource is webServiceDataSource1 and you are wondering how to use the data of the second WebServiceDataSource, is that correct?

There are basically two approaches that I would recommend choosing from:

  • Create a Report Parameter whose data source is the webServiceDataSource2 and the ValueMember and Value properties use the field with the base64 string. Then, you will be able to use that value anywhere in the report - Using Report Parameters in Expressions Explained - Telerik Reporting.
  • (Not Recommended)Nest a second data item, inside the original one, and put the PictureBox in the nested item. The nested item should have its DataSource set to webServiceDataSource2, this way you will be able to use the base64 string field but be aware that this might result in the PictureBox being rendered more than once due to the nature of data items.

Please test the two approaches and if you have any additional questions, or if you need further assistance, please send me the report alongside some sample data that I could use to prepare a solution locally.

Thank you for using Telerik Reporting!

Regards,
Dimitar
Progress Telerik

Brand new Telerik Reporting course in Virtual Classroom - the free self-paced technical training that gets you up to speed with Telerik and Kendo UI products. Check it out at https://learn.telerik.com/.
Neil N
Top achievements
Rank 2
Iron
Iron
Veteran
commented on 10 Apr 2023, 02:55 PM

I'm now passing the base64 string as a report parameter and assigning =Parameters.photoBase64.Value as the picturebox value works. But how do I avoid having the picturebox showing an error if "" (i.e., no picture) is passed?
Dimitar
Telerik team
commented on 13 Apr 2023, 09:34 AM

You can condition to the Value expression used by the PIctureBox. For example, you may check if the value of the report parameter is null or an empty string and you may return some default image:

= Parameters.Parameter1.Value Is Null Or Parameters.Parameter1.Value = "" ? default_image : Parameters.Parameter1.Value

The above expression could also be implemented with the If(Condition, ReturnedIfTrue, ReturnedIfFalse) conditional function. If you do not need to display a default image, you can instead use the expression to bind the Visible property of the PictureBox item.

If you need to use more complicated logic, you may instead create a custom function that takes the value of your parameter and return a default image when there is no picture in the report parameter value - Custom User Functions Explained - Telerik Reporting.

Let me know if you have additional questions.

Tags
PictureBox
Asked by
Neil N
Top achievements
Rank 2
Iron
Iron
Veteran
Answers by
Dimitar
Telerik team
Share this question
or