ASP.NET
  Home arrow ASP.NET arrow Page 2 - Binding Data to the ReportViewer Control D...
ASP Free Forums 
.NET  
ASP  
ASP Code  
ASP.NET  
ASP.NET Code  
BrainDump  
C#  
Code Examples  
Database  
Database Code  
IIS  
Microsoft Access  
MS SQL Server  
Silverlight  
Visual Basic.NET  
Windows Scripting  
Windows Security  
XML  
Mobile Linux 
App Generation ROI 
IBM® developerWorks 
ASP Web Hosting  
ASP.NET Web Hosting 
Windows Web Hosting
 
Weekly Newsletter
 
Developer Updates  
Free Website Content 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us Get Paid 
Request Media Kit
Contact Us 
Site Map 
Privacy Policy 
Support 
 USERNAME
 
 PASSWORD
 
 
  >>> SIGN UP!  
  Lost Password? 
ASP.NET

Binding Data to the ReportViewer Control Dynamically in ASP.NET 2.0
By: Jagadish Chaterjee
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 5 stars5 stars5 stars5 stars5 stars / 41
    2006-11-13

    Table of Contents:
  • Binding Data to the ReportViewer Control Dynamically in ASP.NET 2.0
  • Binding a SELECT statement to a ReportViewer control in ASP.NET 2.0: code
  • Binding an XML document to a ReportViewer control in ASP.NET 2.0
  • Binding a text file (with comma separated values or CSV) to a ReportViewer control in ASP.NET 2.0
  • Binding a customized ObjectDataSource (or business logic) to a ReportViewer control in ASP.NET 2.0
  • Binding a customized ObjectDataSource (or business logic) to a ReportViewer control in ASP.NET 2.0: code

  • Rate this Article: Poor Best 
      ADD THIS ARTICLE TO:
      Del.ici.ous Digg
      Blink Simpy
      Google Spurl
      Y! MyWeb Furl
    Email Me Similar Content When Posted
    Add Developer Shed Article Feed To Your Site
    Email Article To Friend
    Print Version Of Article
    PDF Version Of Article
     
     
    ADVERTISEMENT


    Binding Data to the ReportViewer Control Dynamically in ASP.NET 2.0 - Binding a SELECT statement to a ReportViewer control in ASP.NET 2.0: code


    (Page 2 of 6 )

    Once you have created the datasets and reports as given in the previous section, we need to work with the ReportViewer control to render the data based on the dynamic SELECT.

    Drag a ReportViewer control onto the default.aspx  and modify your code-behind file in such a way that it looks something like the following:

    ImportsMicrosoft.Reporting.WebForms

    ImportsSystem.Data

    ImportsSystem.Data.Sqlclient

    PartialClass _Default

        Inherits System.Web.UI.Page

        Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load

            'Set the processing mode for the ReportViewer to Local

            ReportViewer1.ProcessingMode = ProcessingMode.Local

            Dim rep As LocalReport = ReportViewer1.LocalReport

            rep.ReportPath = "SampleReport.rdlc"

            Dim ds As DataSet = GetSalesData()

            'Create a report data source for the sales order data

            Dim dsSalesOrder As New ReportDataSource()

            dsSalesOrder.Name = "SalesData_Data"

            dsSalesOrder.Value = ds.Tables("SalesData")

            rep.DataSources.Add(dsSalesOrder)

        End Sub

        Private Function GetSalesData()

            Dim ds As New DataSet

            Dim sqlSalesData As String = _

                "SELECT SalesPersonID, FirstName, " & _

                "       SalesQuota, SalesYTD, SalesLastYear " & _

                "FROM   Sales.vSalesPerson "

            Using connection As New SqlConnection( _

                          "Data Source=(local)sql2k5; " & _

                          "Initial Catalog=AdventureWorks; " & _

                          "Integrated Security=SSPI")

                Dim command As New SqlCommand(sqlSalesData,
    connection)

                Dim salesOrderAdapter As New SqlDataAdapter(command)

                salesOrderAdapter.Fill(ds, "SalesData")

                salesOrderAdapter.Dispose()

                command.Dispose()

            End Using

            Return ds

        End Function

    EndClass

    More ASP.NET Articles
    More By Jagadish Chaterjee


       · Hello guys! This is second in series focusing on reporting in ASP.NET 2.0. In this...
       · I am trying to generate a report using the report viewer control in VS2005 with the...
       · Great article, thanks for posting it!One small edit though. To get this to...
       · I am getting the following error when trying to render my report. I am not using any...
       · Hi,I tried to use this code but i got an error "A data source instance has not...
     

    ASP.NET ARTICLES

    - Adding Content to a Static ASP.NET Website
    - Building a Static ASP.NET Website in a Basic...
    - Develop Your First ASP.NET Website with Visu...
    - Run ASP.NET in Windows XP Home with Cassini ...
    - How to Test a Web Application
    - How to Add Code and Validation Controls to a...
    - Working in Source and Split Views to Build a...
    - How to Build a Web Form for a One-Page Web A...
    - How to Develop a One-Page Web Application
    - An ASP.NET Web Application in Action
    - Developing ASP.NET Web Applications
    - An Introduction to ASP.NET Web Programming
    - Introduction to the ADO.NET Entity Framework...
    - Completing an In-Text Advertising System und...
    - Programming an In-Text Advertising System un...





    © 2003-2009 by Developer Shed. All rights reserved. DS Cluster 4 Hosted by Hostway
    For more Enterprise Application Development news, visit eWeek