Search code examples
c#asp.netdatasourcereportviewer

ASP.NET C# reportviewer Parameter


I am new to report viwer, I wanted to know that how to pass the select parameter to report viewer and also to data source? I need to pass the start date and end date to the data source for filtering data and also show in report viewer. Anyone suggest?

>     <rsweb:ReportViewer ID="Log_ReportViewer" runat="server" Height="545px" Width="962px" Font-Names="Verdana" Font-Size="8pt"
> WaitMessageFont-Names="Verdana" WaitMessageFont-Size="14pt">
>         <LocalReport ReportPath="Reporting\ReportRDLC File\LogReport.rdlc">
>             <DataSources>
>                 <rsweb:ReportDataSource DataSourceId="SqlDataSource1" Name="Log" />
>             </DataSources> 
>         </LocalReport>
>     </rsweb:ReportViewer>
>     <asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:InvControlConnectionString %>"
> ProviderName="<%$
> ConnectionStrings:InvControlConnectionString.ProviderName %>"
> SelectCommand="SELECT * FROM logs WHERE log_createDate >= startDate AND log_createDate >= endDate">
>         <SelectParameters>
>             <asp:QueryStringParameter Name="endDate" QueryStringField="endDate" />
>             <asp:QueryStringParameter Name="startDate" QueryStringField="startDate" />
>         </SelectParameters>
>     </asp:SqlDataSource> </asp:Content>

Solution

  • Through the code behind, like that:

    ReportParameter[] parameters = new ReportParameter[yournumberofparamaters];
    parameters[0] = new ReportParameter("name", value);
    parameters[1] = new ReportParameter("name", value);
    parameters[2] = new ReportParameter("name", value);
    this.Log_ReportViewer.LocalReport.SetParameters(parameters);