Thursday, November 15, 2012

Crystal Report DataBinding with ASP.NET - Simple Example

Following Tutorial describes simple data binding for a crystal report.

Step 1

Create your data source. Below is a sample datasource for bind to the report

 private DataTable GetDatatable()

        DataTable DT = new DataTable();
        DT.Columns.Add("ID", typeof(Int32));
        DT.Columns.Add("Name", typeof(string));
        DT.Columns.Add("Country", typeof(string));

        DT.Rows.Add(1, "chamara", "sri lanaka");
        DT.Rows.Add(2, "Ajith", "India");
        DT.Rows.Add(3, "Sam", "America");
        return DT;

Step 2
Add a new dataset and name it as DataSetReport.

Step 3
Right click on the dataset design view-> Add new datatable
Design the dataset as follows.

Step 4
Now Add a new crystal report. Right click on the Database fields and select database expert

Step 5
Under ProjectData select the dataset you have just created and click on the arrow to add it to the selected tables.

Step 6
Design your report.

Step 7
Now add a CrystalReportReportViwer Control to your .aspx page and add the following source code.

protected void Page_Load(object sender, EventArgs e)

    private void LoadReport()
        ReportDocument crystalReport = new ReportDocument();
        CrystalReportViewer1.ReportSource = crystalReport;

Step 8

Run your .aspx page and see the report

1 comment:
Write comments
Recommended Posts × +