How to create Dynamic Report in RDLC? [Resolved]

Posted by Amatya under C# on 7/1/2016 | Points: 10 | Views : 7152 | Status : [Member] | Replies : 3
How to create Dynamic Report in RDLC Steps by step ?

Feel free to share informations.
mail Id ' adityagupta200@gmail.com
Thanks



Responses

Posted by: A2H on: 7/3/2016 [Member] [MVP] Silver | Points: 50

Up
0
Down

Resolved
If you have data in datatable then above code to fetch data from database wont work completely. You just need to change the data fetching part to use LINQ to fetch data from datatable
Sample Code

List<YourClassName> employee = (from emp in dtEmployees.AsEnumerable()
where [Your condition]
select emp).ToList();
//Assign the dataset to Report Datasource
ReportDataSource datasource = new ReportDataSource("DataSet1", employee);
//Clear all assiged datasource in reportviewer
ReportViewer1.LocalReport.DataSources.Clear();
//Assiged the filtered DataSource to ReportViewer
ReportViewer1.LocalReport.DataSources.Add(datasource);
//Refrest the ReportViewer
ReportViewer1.LocalReport.Refresh();


Thanks,
A2H
My Blog

Amatya, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: A2H on: 7/3/2016 [Member] [MVP] Silver | Points: 25

Up
0
Down
You can try with the below implemenation. To code is adjusted to CustomerTable in AdventureWorks datatable. You have to adjust this as per you database tables

HTML
<asp:TextBox ID="TextBox1" runat="server" AutoPostBack="True" OnTextChanged="TextBox1_TextChanged2"></asp:TextBox>
<rsweb:ReportViewer ID="ReportViewer1" runat="server" Font-Names="Verdana" Font-Size="8pt" WaitMessageFont-Names="Verdana"
WaitMessageFont-Size="14pt" Width="750px">
<LocalReport ReportPath="Report1.rdlc">
<DataSources>
<rsweb:ReportDataSource DataSourceId="ObjectDataSource1" Name="DataSet1" />
</DataSources>
</LocalReport>
</rsweb:ReportViewer>
<asp:ObjectDataSource ID="ObjectDataSource1" runat="server" SelectMethod="GetData"
TypeName="EmptyWebApp.CustomersTableAdapters.AddressTableAdapter"></asp:ObjectDataSource
>

C#:

protected void TextBox1_TextChanged2(object sender, EventArgs e)
{
//Connection string
string CS = ConfigurationManager.ConnectionStrings["AdventureWorks2008R2ConnectionString2"].ConnectionString;
//Create connection object
using (SqlConnection con = new SqlConnection(CS))
{
//Assign query to SQLDataAdapter
SqlDataAdapter da = new SqlDataAdapter("select * from Person.Address where City = @City", con);
//pass the paramter value
da.SelectCommand.Parameters.AddWithValue("@City", TextBox1.Text);
//Create a dataset object
DataSet ds = new DataSet();
//FIll the dataset
da.Fill(ds);
//Assign the dataset to Report Datasource
ReportDataSource datasource = new ReportDataSource("DataSet1", ds.Tables[0]);
//Clear all assiged datasource in reportviewer
ReportViewer1.LocalReport.DataSources.Clear();
//Assiged the filtered DataSource to ReportViewer
ReportViewer1.LocalReport.DataSources.Add(datasource);
//Refrest the ReportViewer
ReportViewer1.LocalReport.Refresh();
}
}




Thanks,
A2H
My Blog

Amatya, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Amatya on: 7/3/2016 [Member] Silver | Points: 25

Up
0
Down
Number of column can change in this condition, and I have my data in DataTable in which the no. of Column can change.
This is work?

Feel free to share informations.
mail Id ' adityagupta200@gmail.com
Thanks

Amatya, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response