0
votes

I have to generate report on .aspx page through Crystal Report, my report includes different tables. I am following below steps to do so:

  1. Create Standard Report Wizard in ASP Web Application in Visual Studio
  2. Add Dataset with Datatable with Columns(same name as column name in SQL query)
  3. Drag & Drop Col names in 'Details Section' (it will automatically add same as heading in "Page Header" Section.
  4. Drag down Section 4 to arrange all data within the Details section
  5. For Columns consuming much area increase their height, all formatting including font styles, text cell allignment , col size etc are easily formatible.
  6. For different part of data(small tables etc), Sub Reports are used

testpage.aspx

<form id="form1" runat="server">
    <asp:Button ID="Button1" runat="server" OnClick="Button1_Click" Text="Back to Input Page" />
<CR:CrystalReportViewer ID="CrystalReportViewer1" runat="server" AutoDataBind="true" ToolPanelView="None" />

testpage.aspx.cs

    public partial class testpage : System.Web.UI.Page
    {
            string ticketgotsession, query;
            string conString =  ConfigurationManager.ConnectionStrings["connectionstring"].ConnectionString;
      protected void Page_Load(object sender, EventArgs e)
      {
        ticketgotsession = Session["ticketno"].ToString();
        ReportDocument crystalReport = new ReportDocument();
        crystalReport.Load(Server.MapPath("~/Crystest4.rpt"));

   //All different queries combined in 1 query & stored in Dataset obj t1 
    test1 t1 = GetQ1("select c1,c2,c3.....c30 
          from table1
          inner join  table2 on ___
          inner join table3 on ___
          inner join table4 on ___
         where cr.ref_num='" + ticketgotsession + "'");

         crystalReport.SetDataSource(t1);
         CrystalReportViewer1.ReportSource = crystalReport;
      }

private test1 GetQ1(string query)
{
    SqlCommand cmd1 = new SqlCommand(query);
    using (SqlConnection con = new SqlConnection(conString))
    {
        using (SqlDataAdapter sda1 = new SqlDataAdapter())
        {
            cmd1.CommandType = CommandType.Text;
            cmd1.Connection = con;

            sda1.SelectCommand = cmd1;

            using (test1 t1 = new test1())
            {   //DataTable4 was empty table of dataset test1 with Exactly same name as all Col names in the query
                sda1.Fill(t1,"DataTable4");
                return t1;
            }
        }
    }
}

Below is the report designed so far (Encircled: cell borders for cells created using Lines manually, data exceeds out of 1 cell or sometimes it overprints over another content).
enter image description here

Links have also been referred : auto-adjust size using datatables and Using Tight Horizontal

However, after many experiments, below was observed with Can Grow & Tight Horizontal feature:

"When Can Grow & Tight Horizontal both are Enabled then Columns are Vertically Expanded But not Horizontally, no text truncated"

"When Tight Horizontal is Enabled, Border will be trimmed to match the size of each individual record."

But nothing worked.

As there is Grid View in asp.net, which aligns data dynamically in tabular layout, I am looking for similar feature in Crystal Report, so that I don't have to drag and drop each data field then resize, set boundaries each of them manually.

Thanks in advance!!

2

2 Answers

0
votes

Does the user see the report preview? Or do you need to deliver the end result as print/export format? If so, which format?

0
votes

In that case, you have 2 main options:

  1. Improve the layout design, possibly using dynamic size/position expressions. If font is proportional you can create or use a 3rd-party Crystal UFL (User Function Library) to compute size for a given content and font.

  2. In code, use a grid control or HTML table, convert result to image, and display the image in the report. Again, you can create or use a 3rd-party Crystal UFL to do that. Here is an example of output from a Crystal formula using a 3rd-party UFL that converts HTML text to an image for embedding in the report:enter image description here