I have to generate report on .aspx page through Crystal Report, my report includes different tables. I am following below steps to do so:
- Create Standard Report Wizard in ASP Web Application in Visual Studio
- Add Dataset with Datatable with Columns(same name as column name in SQL query)
- Drag & Drop Col names in 'Details Section' (it will automatically add same as heading in "Page Header" Section.
- Drag down Section 4 to arrange all data within the Details section
- For Columns consuming much area increase their height, all formatting including font styles, text cell allignment , col size etc are easily formatible.
- 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).
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!!
