Click here to Skip to main content
15,892,927 members
Please Sign up or sign in to vote.
5.00/5 (1 vote)
See more:
C#
<rsweb:ReportViewer ID="ReportViewer2"  runat="server" Font-Names="Verdana" 
        Font-Size="8pt" InteractiveDeviceInfos="(Collection)"
        WaitMessageFont-Names="Verdana" WaitMessageFont-Size="14pt" Width="800px" 
        Height="600px" Visible="true">
        <LocalReport ReportPath="rdlc\Report5.rdlc">
             <DataSources>
                <rsweb:ReportDataSource DataSourceId="SqlDataSource2" Name="DataSet1" />
            </DataSources>
        </LocalReport>
    </rsweb:ReportViewer>

    <asp:SqlDataSource ID="SqlDataSource2" runat="server" 
        ConnectionString="<%$ ConnectionStrings:ConnectionString %>" 
        SelectCommand="SELECT * FROM [m_aom] WHERE [m_month] = @m_month">
        
        <SelectParameters>
            <asp:QueryStringParameter Name="m_month" QueryStringField="m_month" 
                Type="Int32" />
        </SelectParameters>

    </asp:SqlDataSource>


I no idea on how to declare the Select Parameter in the behind C# coding, Please any one help?!

There is not other related coding in the behind coding now.
Posted

Try this Code format in Code Behind

C#
ReportViewer1.LocalReport.DataSources.Add
(new Microsoft.Reporting.WebForms.ReportDataSource("DataSet1", dt.ToList()));
           ReportViewer1.LocalReport.ReportPath =
           Server.MapPath("_MedicalReimburseReport.rdlc");
           ReportViewer1.LocalReport.Refresh();

           List<reportparameter> parameters = new List<reportparameter>();
           parameters.Add(new ReportParameter("coveredDateFrom", txtFrom.Text));
           parameters.Add(new ReportParameter("coveredDateTo", txtTo.Text));
           parameters.Add(new ReportParameter("workSiteCode", worksiteCode));
           ReportViewer1.LocalReport.SetParameters(parameters);
 
Share this answer
 
v4
Comments
tomy_hkcg 8-Feb-12 2:59am    
thanks, gonna try it now, but where do i put this code in, inside the pageload?
zyck 8-Feb-12 3:27am    
yes! don't forget to change parameters
zyck 8-Feb-12 4:01am    
please vote for my answer if this will help you
thanks
Hi,

Try this if could help...

C#
ReportDocument crpt = new ReportDocument();
string rptLoc = String.Empty;
DataSet1 ds = new DataSet1();

private void AddParameter(ReportDocument reportDocument, string value, string parameterName)
{
    ParameterFieldDefinitions prmDef = reportDocument.DataDefinition.ParameterFields;
    ParameterValues prmVal = new ParameterValues();
    ParameterDiscreteValue prmDiscreteVal = new ParameterDiscreteValue();
    prmDiscreteVal.Value = value;
    prmVal.Add(prmDiscreteVal);
    ParameterFieldDefinition prmFD = prmDef[parameterName];
    try
    {
        prmFD.ApplyCurrentValues(prmVal);
        prmFD.ApplyDefaultValues(prmVal);
    }
    catch (Exception)
    {
        Response.Redirect("~\\Login.aspx");
    }
}
// Some code here...
rptLoc = CrystalReportSource1.Report.FileName;
crpt.Load(rptLoc);
crpt.SetDataSource(ds);
// Some code here...
AddParameter(crpt, lstReport[0].CardNumber.ToString(), "CardNumber");

// Some code here...
CrystalReportViewer1.ReportSource = crpt;



Regards,
 
Share this answer
 
Comments
tomy_hkcg 8-Feb-12 2:58am    
doesn't, actually it is something like this but inside a function? i have no idea what function i should create.

SqlDataSource2.SelectParameters["m_month"].DefaultValue = new_m_month.SelectedItem.Value;
Al Moje 8-Feb-12 3:54am    
Sorry! I assumed that your question is about crystal report...
Any way should create a corresponding parameter fields in your rpt template file:

Above example has a corresponding parameter field ‘CardNumber’ in rpt file.

Example:

CrystalReportSource1.Report.FileName = Server.MapPath("") + "\\Reports\\StudentMast.rpt";

// Some code here…string valueToPass = “1234567890”;

AddParameter(crpt, valueToPass, "CardNumber"); // Call the private void AddParameter passing three parameters
Hi,

You can view this link
http://forums.asp.net/t/1292760.aspx
 
Share this answer
 
v2
Comments
tomy_hkcg 8-Feb-12 2:41am    
is that coding for VB? i am using C# r, thanks anyway
Just add this inside the behind coding

C#
SqlDataSource2.SelectParameters["m_month"].DefaultValue = m_month.SelectedItem.Value;
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900