Asp.net & C# RDLC Report Generation

.aspx.cs file

using System.Configuration;

using Microsoft.Reporting.WebForms;
using System.Data;
using System.Data.SqlClient;

protected void btnGenerateTranscript_Click(object sender, EventArgs e)
{
String ConString = ConfigurationManager.ConnectionStrings[“RegistrationandExamination”].ConnectionString.ToString();
String SqlString = “sp_TranscriptReportDataGeneration_Old”;
SqlCommand cmd = new SqlCommand();
SqlConnection con = new SqlConnection(ConString);
con.Open();
cmd.Connection = con;
cmd.CommandType = CommandType.StoredProcedure;
cmd.CommandText = SqlString;
cmd.Parameters.AddWithValue(“@StudentId”, txtStudentRoll.Text.Trim());
SqlDataAdapter da = new SqlDataAdapter(cmd);
DataSet ds = new DataSet();
da.Fill(ds);

ReportDataSource rds = new ReportDataSource(“dsTranscriptAdditionalSheet”, ds.Tables[0]);
viewer.ProcessingMode = ProcessingMode.Local;
viewer.LocalReport.ReportPath = Server.MapPath(“rptTranscriptAdditionalSheet.rdlc”);
viewer.LocalReport.DataSources.Add(rds);
viewer.LocalReport.Refresh();
}

.aspx file
<%@ Register Assembly=”Microsoft.ReportViewer.WebForms, Version=10.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a”
Namespace=”Microsoft.Reporting.WebForms” TagPrefix=”rsweb” %>
<!DOCTYPE html PUBLIC “-//W3C//DTD XHTML 1.0 Transitional//EN” “http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd”&gt;
<html xmlns=”http://www.w3.org/1999/xhtml”&gt;
<head runat=”server”>
<title></title>
</head>
<body style=”background-image: url(App_Themes/Images/bg_body_ie.png); background-repeat: repeat-x;”>
<form id=”form1″ runat=”server”>
<div align=”center”>
<fieldset style=”border-color: Black; width: 1px; width: 1000px;”>
<fieldset style=”border-color: Black; width: 1px; width: 600px;”>
<div align=”center”>
<table width=”80%”>
<tr>
<td align=”right”>
Student Roll
</td>
<td>
:
</td>
<td width=”150px”>
<asp:TextBox ID=”txtStudentRoll” runat=”server”></asp:TextBox>
</td>
<td align=”left”>
<asp:Button ID=”btnGenerateTranscript” runat=”server” Text=”Generate” OnClick=”btnGenerateTranscript_Click” />
</td>
</tr>
</table>
</div>
</fieldset>
<div align=”center”>
<rsweb:ReportViewer ID=”viewer” runat=”server” Font-Names=”Verdana” Font-Size=”8pt”
Height=”750px” InteractiveDeviceInfos=”(Collection)” WaitMessageFont-Names=”Verdana”
WaitMessageFont-Size=”14pt” Width=”800px”>
</rsweb:ReportViewer>
</div>
</fieldset>
</div>
<asp:ScriptManager ID=”ScriptManager1″ runat=”server”>
</asp:ScriptManager>
</form>
</body>
</html>

 

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s