This is a migrated thread and some comments may be shown as answers.

ItemDataBound Access DataSet Contents

3 Answers 587 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
Bruce Hochstetler
Top achievements
Rank 2
Bruce Hochstetler asked on 26 Sep 2007, 04:10 PM
Hi,

I was looking through the forums, demos, and online documentation and could not find any details on how to access DataItems in a ItemDataBound event handler. I have a dataset bound to the report's datasource. One of the data items has the name of a gif to use for the column. So I need to get the data item, get the name and bind it to the column in the report. I hope that's clear. It would be nice to have more robust documentation regarding the event handlers.

Thanks,
Bruce

3 Answers, 1 is accepted

Sort by
0
Ivan
Telerik team
answered on 28 Sep 2007, 02:34 PM
Hi Bruce,

To bind a picture box report item to the database you can set its Value property to a data column (see the rightmost picture box from the attached sample). For example
    PictureBox3.Value = "=PictureFileName"

where PictureFileName is the column name from the report's DataSource.

If you prefer to access data items of the current DataSource record from ItemDataBinding or ItemDataBound event handlers, you should use the following construction (the sender is the first argument in handlers' argument list):

// C# 
Telerik.Reporting.Processing.ReportItemBase itemBase = 
    (Telerik.Reporting.Processing.ReportItemBase)sender; 
string name = (string)((System.Data.DataRowView)(itemBase.DataItem))["filename"]; 
 

To load an image from a file you can use the System.Drawing.Image.FromFile() method but note that you should feed it with the real file name, i.e. if the database contains only the pictures' names you should reconstruct the full file names. The FromFile() method works with any image type that the GDI+ can operate with, including jpg, png and gif.

There are some differences when working with
ItemDataBinding or ItemDataBound event handlers:
  • inside ItemDataBinding you should assign the image to the Value property of Telerik.Reporting.PictureBox item - here we are working with report items from the report definition structure;
     
  • inside ItemDataBound you should assign the image to the ImageData property of Telerik.Reporting.Processing.PictureBox item - here we are working with the items from the processed report structure.
In have attached the sample solution. It it I am using the hard coded path to the pictures ("c:\pix\") but you can replace it with any other form, for example you can use HttpServerUtility.MapPath() method in your website projects.
Note: you need to copy the Pix folder from attached zip archive into "c:\".
 
 
Best wishes,
Ivan
the Telerik team

Instantly find answers to your questions at the new Telerik Support Center
0
Bartlomiej Wojdyna
Top achievements
Rank 1
answered on 15 Jun 2011, 02:44 PM
Hello,

According to your post from Sep 28, 2007 I was trying to use property DataItem (in ItemDataBound event)
I use Telerik Q1 2011 but I can not see this property.

Could you help me?

Regards
Bart
0
Steve
Telerik team
answered on 15 Jun 2011, 03:04 PM
Hi Bartlomiej,

The following KB article contains the answer to your question:ReportItemBase.DataItem property (Telerik.Reporting.Processing) has been replaced by property DataObject.
Generally when you find such an old forum, the chances are it is already obsolete, so checking the documentation or newer threads for the answer is recommended.

Greetings,
Steve
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
Tags
General Discussions
Asked by
Bruce Hochstetler
Top achievements
Rank 2
Answers by
Ivan
Telerik team
Bartlomiej Wojdyna
Top achievements
Rank 1
Steve
Telerik team
Share this question
or