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

subreport conditional visible

3 Answers 412 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
Steven
Top achievements
Rank 1
Steven asked on 04 Jan 2008, 03:04 AM
Hi,

Is there any way to make a subreport visible according to some Fields value?

For example, I have a purchase order report, one purchase order may contain multiple purchase order items. The sub report list the items belong to its purchase order. If there is no purchase order item for one purchase order, the subreport should not visible, or display some friendly message saying that: No items for this purchase order. I can have a field value called LineCount to count the number of items for each purchase order.

Thanks a lot

3 Answers, 1 is accepted

Sort by
0
Ivan
Telerik team
answered on 04 Jan 2008, 06:29 PM
Hello Steven,

Thank you for contacting Telerik Support.

Yes, it is possible to hide a sub report item conditionally. You should implement an ItemDataBound event handler for the sub report item and inside it set the Visible property to false each time you want to hide the sub report:

private void subReport1_ItemDataBound(object sender, System.EventArgs e) 
    Telerik.Reporting.Processing.ReportItemBase item = 
        (Telerik.Reporting.Processing.ReportItemBase)sender; 
    item.Visible = this.showDetails; 
 

I have attached a sample solution which demonstrates this technique.

I hope this information helps.

Sincerely yours,
Ivan
the Telerik team

Instantly find answers to your questions at the new Telerik Support Center
0
Steven
Top achievements
Rank 1
answered on 08 Jan 2008, 02:35 AM
Thanks for your reply. it help me a lot.

If I have a textbox_ItemDataBound and subreport_ItemDataBound in the detail section, the subreport_ItemDataBound always run first, and then the textbox_ItemDataBound run. Is there any way I can run the textbox_ItemDataBound first?

Because I want to access a value from the datasource in my object list, and use this value to determine whether it's corresponding subreport is visible or invisible. So my approach is bind the value to a textbox and use textbox_ItemDataBound to get this value in the class method, then I can set whether the subreport is visble or invisible in subreport_ItemDataBound.

Many thanks,

Steven
0
Ivan
Telerik team
answered on 09 Jan 2008, 08:34 AM
Hi Steven,

Thank you coming back to Telerik support.

When visibility of report items depends on data value from data source we have two possibilities:
  1. when we manipulate one report item we can use it's ItemDataBound (or ItemDataBinding) event handler to manipulate item's visibility state.
    For example see ReportMaster report;
  2. when we manipulate some report items we can use ItemDataBinding event handler of detail section (or other report item that contains the items we are dealing with (for example group section or panel) to set a flag for visibility state (ReportMaster2.showSubReport) and later to set Visible property of all involved report items in their ItemDataBinding/Bound event handlers.
    For example see ReportMaster2 report;
Please note, how we access the current data row in event handlers:
Telerik.Reporting.Processing.ReportItemBase item = 
    (Telerik.Reporting.Processing.ReportItemBase)sender; 
DataRowView dataRow = (DataRowView)item.DataItem; 
object o = dataRow["ID"]; 
 

this way we eliminate the need to data-bound some text box and later to inspect it's value.

I hope this information helps.

Sincerely yours,
Ivan
the Telerik team

Instantly find answers to your questions at the new Telerik Support Center
Tags
General Discussions
Asked by
Steven
Top achievements
Rank 1
Answers by
Ivan
Telerik team
Steven
Top achievements
Rank 1
Share this question
or