Sunday, September 20, 2009

Hide and Show Crystal Report’s Sub Report when we need

Refer to my previous post assume you want to display the sub report only data is available. therefore you can check the data for row availability and if rows are exists you can  display the report. In my example we are placed our sub report in section 4 in main report. thus we can use following code to display the sub report only data is available.

if (dts.Rows.Count > 0)
{
Ci.Subreports["SubBalance"].SetDataSource((DataTable)dts);
}
else
{
Ci.ReportDefinition.Sections[3].SectionFormat.EnableSuppress = true;
}

5 comments:

Nuwan said...

Thank you very much for the code. I was searching this thing for few days. Now I fixed my problem. Thank you again..

Melick Rajee said...

you are most welcome Nuwan :-)

vick said...

Hey, thank you for ur post. How do we just suppress subReport without any condition (in C#)

Arun Prasad said...

Thank you very much for this code. Was struggling to get this done and with your code, its smooth sailing over this. Thanks a lot Melick :)

Melick Rajee said...

Thank You Arun :-)