locked
Report Viewer RRS feed

  • Question

  • User-1240662851 posted

    hi all 

    I need to bind the Report Viewer by datatable and also i need to insert a header and footer to that report like logo adress bla bla.. these are constants for the pages and reports in the website 

    Please help me Please Iam using VS2010 C#

    Monday, February 11, 2013 5:19 AM

Answers

  • User1630798415 posted
    • Open a client report definition (.rdlc) file in graphical design mode.

    • On the Report menu, click Page Header or Page Footer. Page Header and Page Footer are toggle items on the Report menu. When enabled, a Page Header or Page Footer section appears on the design surface.

      Alternatively, right-click in the empty area outside of the design surface, and then click Page Header or Page Footer.

    • Drag/Add the logo to the Page Header or Page Footer area

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Tuesday, February 12, 2013 6:15 AM
  • User1630798415 posted

    Firstly you should check whether your dataset has data.

    Secondly you  can add 'ReportViewer1.LocalReport.Refresh();' code at the end of ReportViewer1_DataBinding event.

    protected void populateReportViewer()
        {
            StocksCls result = new StocksCls ();
            DataTable dt =    result.getItemsPerCategory(DropDownList1.SelectedItem.Text);
            ReportDataSource rds = new ReportDataSource("DataSet1_DataTable1", dt);
            ReportViewer1.LocalReport.DataSources.Clear();
            ReportViewer1.LocalReport.DataSources.Add(rds);
            ReportViewer1.LocalReport.Refresh(); 
    
        }
    

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Wednesday, February 13, 2013 12:00 AM

All replies

  • User-1240662851 posted

    santosh.jagdale

    please refer these two links 

    i need to insert my company logo in the report as a headder

    Monday, February 11, 2013 7:59 AM
  • User1630798415 posted
    • Open a client report definition (.rdlc) file in graphical design mode.

    • On the Report menu, click Page Header or Page Footer. Page Header and Page Footer are toggle items on the Report menu. When enabled, a Page Header or Page Footer section appears on the design surface.

      Alternatively, right-click in the empty area outside of the design surface, and then click Page Header or Page Footer.

    • Drag/Add the logo to the Page Header or Page Footer area

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Tuesday, February 12, 2013 6:15 AM
  • User-1240662851 posted

    Thank You So much Santhosh one more help how can i bind dinamically reportviewe i have code but getting error

    My code is 

    Aspx:

    <%@ Page Title="" Language="C#" MasterPageFile="~/MasterPage.master" AutoEventWireup="true" CodeFile="Reports.aspx.cs" Inherits="Reports" %>
    
    <%@ Register assembly="CrystalDecisions.Web, Version=10.5.3700.0, Culture=neutral, PublicKeyToken=692fbea5521e1304" namespace="CrystalDecisions.Web" tagprefix="CR" %>
    
    <%@ Register assembly="Microsoft.ReportViewer.WebForms, Version=10.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" namespace="Microsoft.Reporting.WebForms" tagprefix="rsweb" %>
    
    <asp:Content ID="Content1" ContentPlaceHolderID="head" Runat="Server">
    </asp:Content>
    <asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server">
        
        <asp:ScriptManager ID="ScriptManager1" runat="server">
        </asp:ScriptManager>
        <rsweb:ReportViewer ID="ReportViewer1" runat="server" AsyncRendering="False" 
            BorderColor="#FFFFCC" BorderStyle="Double" CssClass="separator" 
            Font-Names="Verdana" Font-Size="8pt" InteractiveDeviceInfos="(Collection)" 
            WaitMessageFont-Names="Verdana" WaitMessageFont-Size="14pt" Width="">
            <ServerReport DisplayName="Test Report" />
            <LocalReport DisplayName="Test Report" ReportPath="Report1.rdlc">
                <DataSources>
                    <rsweb:ReportDataSource DataSourceId="ObjectDataSource2" Name="DataSet1" />
                </DataSources>
            </LocalReport>
        </rsweb:ReportViewer>
        <asp:ObjectDataSource ID="ObjectDataSource2" runat="server" 
            SelectMethod="GetData" TypeName="DataSet1TableAdapters.reportTableAdapter">
        </asp:ObjectDataSource>
        
    </asp:Content>
    

    .CS

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Web;
    using System.Web.UI;
    using System.Web.UI.WebControls;
    using System.Data.SqlClient;
    using System.Data;
    using System.Text;
    using System.Collections;
    using System.Configuration;
    using Microsoft.Reporting.WebForms;
    
    public partial class Reports : System.Web.UI.Page
    {
        SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["DC"].ConnectionString.ToString());
        SqlCommand cmd;
        SqlDataAdapter da;
        DataTable dt;
        DataSet ds = new DataSet();
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                cmd = new SqlCommand("select  ro.R_ID,ro.Test_Dec,r.Mainval+'/'+r.Maxval as MinvalMaxVal,r.UOM,ro.Result,ro.Status from ReportMaster as ro inner join Patient_Investigation as ip on ip.P_In_ID=ro.PIN_ID inner join  Test_Master as t on t.Test_Dec=ro.Test_Dec inner join RangeMaster as r on r.Item_ID=t.Test_ID where ro.Status=1", con);
                da = new SqlDataAdapter(cmd);
                da.Fill(ds, "Dataset1");
                var report = new LocalReport();
                this.ReportViewer1.Reset();
                this.ReportViewer1.LocalReport.ReportPath = Server.MapPath("Report1.rdlc");
                ReportDataSource rds = new ReportDataSource("dsNewDataSet", getData());
                this.ReportViewer1.LocalReport.DataSources.Clear();
                this.ReportViewer1.LocalReport.DataSources.Add(rds);
                this.ReportViewer1.DataBind();
                this.ReportViewer1.LocalReport.Refresh();
            }
        }
    
        private void rptGetDataset()
        {
            DataSet ds = new DataSet();
            ds.DataSetName = "dsNewDataSet";
            string sql = "";
            sql = "select  ro.R_ID,ro.Test_Dec,r.Mainval+'/'+r.Maxval as MinvalMaxVal,r.UOM,ro.Result,ro.Status from ReportMaster as ro inner join Patient_Investigation as ip on ip.P_In_ID=ro.PIN_ID inner join  Test_Master as t on t.Test_Dec=ro.Test_Dec inner join RangeMaster as r on r.Item_ID=t.Test_ID where ro.Status=1";
             da = new SqlDataAdapter(sql, con);
            ds.GetXmlSchema();
            da.Fill(ds);
            ds.WriteXmlSchema("App_Code/DCDataSet.xsd");
            ds.WriteXml("App_Code/XMLFile.xml");
        }
    
        private DataTable getData()
        {
            DataSet dss = new DataSet();
            string sql = "";
            sql = "select  ro.R_ID,ro.Test_Dec,r.Mainval+'/'+r.Maxval as MinvalMaxVal,r.UOM,ro.Result,ro.Status from ReportMaster as ro inner join Patient_Investigation as ip on ip.P_In_ID=ro.PIN_ID inner join  Test_Master as t on t.Test_Dec=ro.Test_Dec inner join RangeMaster as r on r.Item_ID=t.Test_ID where ro.Status=1";
            da = new SqlDataAdapter(sql, con);
            da.Fill(dss);
            DataTable dt = dss.Tables[0];
            return dt;
        }
    
    }

    Getting Error like 

    • A data source instance has not been supplied for the data source 'DataSet1'.
    Please help me 



    Tuesday, February 12, 2013 8:15 AM
  • User1630798415 posted

    Firstly you should check whether your dataset has data.

    Secondly you  can add 'ReportViewer1.LocalReport.Refresh();' code at the end of ReportViewer1_DataBinding event.

    protected void populateReportViewer()
        {
            StocksCls result = new StocksCls ();
            DataTable dt =    result.getItemsPerCategory(DropDownList1.SelectedItem.Text);
            ReportDataSource rds = new ReportDataSource("DataSet1_DataTable1", dt);
            ReportViewer1.LocalReport.DataSources.Clear();
            ReportViewer1.LocalReport.DataSources.Add(rds);
            ReportViewer1.LocalReport.Refresh(); 
    
        }
    

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Wednesday, February 13, 2013 12:00 AM