Keyur

Keyur

  • NA
  • 3
  • 0

Not able to use .rdl report in ASPX Webform using reportviewer

Feb 10 2009 6:29 AM

  

I have created rdl file using "SQL Server Business Intelligent Development Studio". I want to use it in a web page. I have used reportviewer control in the webpage.
Following is the code.

public

partial class OARReport : System.Web.UI.Page

{

private

ReportViewer reportViewer;

protected void Page_Load(object sender, EventArgs e)

{

GenerateReport();

}

private void GenerateReport()

{

reportViewer = ReportViewer11;

// Set Processing Mode

reportViewer.ProcessingMode =

ProcessingMode.Local;

// Set RDL file

reportViewer.LocalReport.ReportPath = Server.MapPath(

"~/ReportOAR.rdl");

 

// Supply a DataTable corresponding to each report data source

reportViewer.LocalReport.DataSources.Clear();

reportViewer.LocalReport.DataSources.Add(

new ReportDataSource("DataSet2", LoadSalesData()));

// Add the reportviewer to the form

this.Controls.Add(reportViewer);

// Process and render the report

reportViewer.DataBind();

}

private DataTable LoadSalesData()

{

SqlConnection con = new SqlConnection("Data Source=xyz;Initial Catalog=xyzClient;user id=me;password=*****");

SqlCommand cmd = new SqlCommand("RPT_TestStatistics", con);

cmd.CommandType =

CommandType.StoredProcedure;

DataSet ds = new DataSet();

SqlDataAdapter sDA = new SqlDataAdapter(cmd);

sDA.Fill(ds);

ds.Tables[0].TableName =

"TestOARStats";

ds.DataSetName =

"DataSet2";

return ds.Tables[0];

}

}



I have set TableName and DataSetName properties according to one i have set while designing the rdl report.



I get following error when i rum my web application.

Server Error in '/SQLReportSampleWebSite1' Application.


Control 'ReportViewer11_ctl01_ctl00_ctl00_ctl00' of type 'ImageButton' must be placed inside a form tag with runat=server.

Note that i have tried this in winform with its reportviewer control and with littlebit change in the code above (like I have to use  reportViewer.RefreshReport(); in winform instead of reportViewer.DataBind(); ) and it works well and generate the report properly. But still i couldn't make why in asp.net reportviewer in doesn't work.
Please let me know if anyone knows the sollution.

 


Answers (1)