How to Change Crystal Report Formatting for Different Customers - Part 1
page 4 of 7
by Eric Landes
Feedback
Average Rating: This article has not yet been rated.
Views (Total / Last 10 Days): 43887/ 188

Custom Formatting your Web Application

Implementing different formatting for your clients using a web application comes out of the box in Crystal Reports .NET. When designing your report, you may notice the option Set CSS Class on the Crystal Reports menu. You can set these classes at design time. See Figure 1 for a screen shot of what this looks like.    

Figure 1

Using the "Set CSS Class" menu option sets the CSS class name in the property of each object for the section selected. For instance, if I select the option AllReportObjectsInGroupHeaderSections, and set the class name to "h1" then each object will have an "h1" in its CSS class property set.  This can be verified by right clicking on the object and selecting Format Object.

These classes assume that you have set up the elements or CSS class names somewhere in your aspx file. In most instances, this means that you have defined your class names in a CSS file referenced in the aspx file displaying your report. In design time you do not have a drop down or intellisense for the available CSS Class names. I heartily recommend this as a new feature Crystal can add to your product. 

You can also set these classes in code. Keep in mind that setting your classes at Design time makes it more difficult to set classes programmatically. You need to write some code to clear each objects class at programming time, and then you can set them. Let us see how we set your CSS classes in code. See listing 2 for the C# code on how to set your class.

Listing 2

protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
Sales crToShow = new Sales();
crToShow.SetCssClass(CrystalDecisions.Shared.ObjectScope.PageHeaderSections, "h1");
crToShow.SetCssClass(CrystalDecisions.Shared.ObjectScope.DetailSections, "body"); 
crToShow.SetCssClass(CrystalDecisions.Shared.ObjectScope.GroupHeaderSections, "h1");
crToShow.SetCssClass(
CrystalDecisions.Shared.ObjectScope.AllReportObjectsInReportHeaderSections, "h1");
CrystalReportViewer1.ReportSource=crToShow;
CrystalReportViewer1.DataBind();
}
}

To set the class, we need to use the reportdocument object of the report we want to display. In this application we use the Sales report, which is part of our project. In this report we want to set the page header section to use the h1 element in the stylesheet ourstyles.css that the default.aspx page uses. To set the page header section we use the ObjectScope object PageHeaderSections. 

One important point to note here is that you set the CSS style by sections. That is the scope used in the SetCSSClass. So there is not a way to set your style by object within the report, but within sections.


View Entire Article

User Comments

No comments posted yet.

Product Spotlight
Product Spotlight 



Community Advice: ASP | SQL | XML | Regular Expressions | Windows


©Copyright 1998-2014 ASPAlliance.com  |  Page Processed at 9/3/2014 12:35:27 AM  AspAlliance Recent Articles RSS Feed
About ASPAlliance | Newsgroups | Advertise | Authors | Email Lists | Feedback | Link To Us | Privacy | Search