So we need to bind the data source to the report at runtime.
The explanations on p 34 of pdf documentation and FAQ of chm help file capture the idea, but we need some additional detail.
This is a web application project. The code we are trying to use to bind a data adapter to the report is below. It was copied from the documentation. It is in the aspx hosting the report viewer which was defined in a separate class project and imported via the references tab. The report has a data source defined in that class.
Where does this code go? It would have to be in the aspx page hosting the report viewer, right? If so, where? The documentation says 'in the report's constructor'. If so, could you please provide an example?
namespace OurWebApp
{
public partial class TelericTest : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
String s = "";
String sSelect = "Select * from jvClaim where Createdt >= '09/01/2008'";
s = cms.sqlClass.getConnString();
SqlConnection conn = new SqlConnection(s);
SqlDataAdapter adapter = new SqlDataAdapter(sSelect, conn);
DataSet dataSet = new DataSet();
adapter.Fill(dataSet);
//this.DataSource = dataSet; ???
//this.DataMember = "Table"; ???
}
}
}
Many thanks,
Mike Thomas
9 Answers, 1 is accepted
Please take a look at the following code library: Use the connectionString from your app's config file and let us know if further help is needed.
Greetings,
Steve
the Telerik team
Check out Telerik Trainer, the state of the art learning tool for Telerik products.
Here is the main question, which was in my first posting in this thread. In the sample app, they put the "Select..." statement in at design time. They put it in what I would call the report's constructor, in the class project. How do we put the select statement in at runtime? For example, the user indicates via input on a web form that he wants the "Top 100" rows, or the "Top 5". I don't think we have any reports where the query is 'canned' at design time.
Again, please look at the example I gave in the first posting. It's from your documentation. I cites the page. Where does this code go? (You can see in the first posting I tried to use the On_Load event of the aspx page hosting the report - this is crealry wrong, so where would it go?) Can the constructor for the report be accessed at runtime? If so how? Could you give an example, remembering that this is a web application.
Many thanks
Mike Thomas
Here is how I would do it:
Use a public property or report parameter to pass in the SQL statuement and then use the NeedDataSource event to populate the report with the code below.
Then you would bind by using report.DataSource = Table
Also, if you use this event, you need to put me.Datasource = Nothing in the Public Sub New after the InitalizeComponent.
Where is the NeedDataSource event trapped? This has to be a common scenario; a user enters parameters into a web page, then the report is called and the data is fed in. That way we can pull only the data we need from SQL Server. At least that's how it works with CrystalReports and the MSFT report viewers.
What I am looking for is a simple 10 step description of how to do this. Surely there has to be an example somewhere?
Here is basically what I expect to do:
-Design the report in a separate class project
- Hook up a data source (on the design computer) to be able to design and preview the report
- 'Import' the report class into a web application project as a reference
(so far so good)
- Make a form where the user enters the parameters for the report & clicks the "GO" button
Call the hosting form which contains the report viewer, select the data into a dataset, attach it to the report, then display the report.
I would love to see a full example or a step by step description of how to do this, or whatever its equivalent would be with the Telerik report control.
Thanks
Mike Thomas
I am trying out the product and have the same questions as Mike had years ago.
I have spent hours searching documentation for how to use this and am running out of time that I can spend and will have to move on to auditing siomething else.
To recap
C# WEB form app
I want to create a report using a data model
Bind data to the report at run time
Hi Charles,
I suggest trying the ObjectDataSource component. Generally, it invokes custom logic to retrieve the data in run-time.
The other option would be to instantiate the report and change its DataSource with code. If you use the HTML5 ASP.NET Web Forms Report Viewer, you need to create a custom ReportSource Resolver, where to instantiate the report definition and modify it as required. You will have to return an InstanceReportSource with ReportDocument containing the modified Report instance.
For your purpose I would work with parameters on db level and create my own UI. Nevertheless, here is a video, that might shed more light - Telerik Reporting - Design Time Support for Parameterized Queries
Cheers
I completely agree - I don't want to pull in a dataset with a million records, then use report parameters to filter the set down to the 35 the user wants to see.
My question is how to tangle the dataset at run time.
Mike Thomas
We've answered your inquiry in the support thread you have opened on the matter.
Best wishes,
Steve
the Telerik team
Check out Telerik Trainer, the state of the art learning tool for Telerik products.
This thread is two years old (as probably our forum has warned you) and its contents are no longer current. In Q1 2010 we've introduced Data Source Components that are responsible for connecting to your data. Check the respective help articles in the latter help section and videos in telerik.tv that elaborate on using them.
All the best,
Steve
the Telerik team
Hi Daniel,
Please, note that this thread is more than 10 years old and some of the information may be outdated.
Depending on the exact scenario, we provide various approaches for attaching data run time to the reports. Here are two popular approaches you may use:
- Modify data source components as explained in the KB article Edit the Report Data Source Components at Runtime.
- Use the NeedDataSource event handler of the data items - Using the NeedDataSource Event to Connect to Data.