This is a migrated thread and some comments may be shown as answers.

Telerik Reporting

1 Answer 118 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
sanjayanthan
Top achievements
Rank 1
sanjayanthan asked on 06 Aug 2012, 08:01 AM
We have purchased Q2 2012 .i have a query in reporting

I need to dyamically bind the columns based on the dataset columns.i have used the sample you have provided, but no luck .
we are not getting any data in reporting panel.

i have created on .aspx page using web form development and used the below shown code.
On button click it has to display 5 rows from the table i have mentioned.
Note: i can see the Getdata() method returns 5 rows in debug mode.But this dataset is not able to bind in report viewer.

what is the wrong in my code.please guide us

ASPX page
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="test.aspx.cs" Inherits="teleriksample.test" %>
<%@ Register Assembly="Telerik.ReportViewer.WebForms, Version=6.1.12.611, Culture=neutral, PublicKeyToken=a9d7983dfcc261be"
    Namespace="Telerik.ReportViewer.WebForms" TagPrefix="telerik" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server"></head>
<body>
    <form id="form1" runat="server">
    <asp:Button ID="Button1" runat="server" Text="Button" onclick="Button1_Click" />
    <telerik:ReportViewer ID="ReportViewer1" runat="server"></telerik:ReportViewer>
    </form>
</body></html>

Code behind part
 public DataTable GetData()
        {
            string conn1 = "Data Source=AES159\\SQLEXPRESS;Initial Catalog=TestDB;User Id=sa;Password=passwd@123;";
            SqlConnection sqlconn = new SqlConnection(conn1);


            string selectCommandText =      "SELECT top 5 * from login_master";

            sqlconn.Open();
            SqlDataAdapter dataAdapter = new SqlDataAdapter(selectCommandText, sqlconn);
            DataTable dataTable = new DataTable();

            dataAdapter.Fill(dataTable);
            sqlconn.Close();
            return dataTable;
        }
        protected void Button1_Click(object sender, EventArgs e)
        {
            Telerik.Reporting.ObjectDataSource objectDataSource = new Telerik.Reporting.ObjectDataSource();
            objectDataSource.DataSource = GetData(); // GetData returns a DataTable
            //objectDataSource.CalculatedFields.Add(new Telerik.Reporting.CalculatedField("FullName", typeof(string), "=Fields.Name + ' ' + Fields.ProductNumber")); // Adding a sample calculated field.

            // Creating a new report
            Telerik.Reporting.Report report1 = new Telerik.Reporting.Report();

            // Assigning the ObjectDataSource component to the DataSource property of the report.
            report1.DataSource = objectDataSource;
            
    
            //// Use the InstanceReportSource to pass the report to the viewer for displaying
            Telerik.Reporting.InstanceReportSource reportSource = new Telerik.Reporting.InstanceReportSource();
            reportSource.ReportDocument = report1;

            //// Assigning the report to the report viewer.
            ReportViewer1.ReportSource = reportSource;

            // Calling the RefreshReport method in case this is a WinForms application.
            //ReportViewer1.RefreshReport();

            ReportViewer1.Visible = true;

        }

regards,
Sanjay

1 Answer, 1 is accepted

Sort by
0
Steve
Telerik team
answered on 09 Aug 2012, 08:47 AM
Hi Sanjay,

The provided examples in the documentation use the base report class (Telerik.Reporting.Report report = new Telerik.Reporting.Report();) for the sake of the example. In reality, you should create an instance of your own report i.e. MyReport report = new MyReport() where MyReport is a report you have already created via the report designer and you have added TextBox items with appropriate Expressions. There is no AutoGenerateColumns feature in Telerik Reporting like with Grid controls, where you just provide data source to the grid and it automatically reflects the columns in your database and creates them automatically. The report is a template that you should create yourself (be it with the report designer or code).

In general if you're using SQL Server, our suggestion is to bind via the SqlDataSource Component which is meant for this very purpose.

Regards,
Steve
the Telerik team

BLOGGERS WANTED! Write a review about Telerik Reporting or the new Report Designer, post it on your blog and get a complimentary license for Telerik Reporting. We’ll even promote your blog and help bring you a few fresh readers. Yes, it’s that simple. And it’s free. Get started today >

Tags
General Discussions
Asked by
sanjayanthan
Top achievements
Rank 1
Answers by
Steve
Telerik team
Share this question
or