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