Querystring parameter

5 posts, 0 answers
  1. david
    david avatar
    210 posts
    Member since:
    May 2007

    Posted 18 Apr Link to this post

    I have Web Forms report viewer ASPX and I'm trying to set a parameter "Parameter1" included in the designer like this:

         if (!IsPostBack)
                {
                    int AppointmentID = Convert.ToInt16((string)Request.QueryString["AppointmentID"]);
                    ReportLibrary.ClientApptInvoice rpt = new ReportLibrary.ClientApptInvoice();
                    rpt.ReportParameters["Parameter1"].Value = AppointmentID;
                }

    when I run the report viewer page I get "Missing or invalid parameter value" and the parameter field which is set visible appears to allow entry.

    What am I missing ? I was trying to follow this - http://docs.telerik.com/reporting/designing-reports-parameters-programmatic-control

    Thanks

  2. Rick
    Admin
    Rick avatar
    5 posts

    Posted 19 Apr Link to this post

    Hello David,

    I see that you instantiate a new report in what looks like the Page_Load event, and I see where you set the parameter value for Parameter1. That all looks correct. I do not see where you actually set that newly instantiated report to be the source of the WebForms ReportViewer. The issue may be that you're not actually loading the same report that you're configuring.

    Try configuring your code like the below. Note that I assign my new report to a ReportSource that is then used by the ReportViewer.

    if (!IsPostBack)
    {
        string fakeQueryString = "String Here";
     
        ClassLibrary1.Report2 rpt = new ClassLibrary1.Report2();
        rpt.ReportParameters["Parameter1"].Value = fakeQueryString;
     
        Telerik.Reporting.InstanceReportSource reportSource = new Telerik.Reporting.InstanceReportSource();
        reportSource.ReportDocument = rpt;
     
        ReportViewer1.ReportSource = reportSource;
    }


    Regards,
    Rick
    Telerik
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
  3. DevCraft banner
  4. david
    david avatar
    210 posts
    Member since:
    May 2007

    Posted 19 Apr in reply to Rick Link to this post

    Rick, thank you, when i follow this (source below) I get an error on : reportViewer1.ReportSource = reportSource;

    "Cannot implicitly convert type 'Telerik.Reporting.InstanceReportSource' to 'Telerik.ReportViewer.Html5.WebForms.ReportSource"

     

                    ReportLibrary.ClientApptInvoice rpt = new ReportLibrary.ClientApptInvoice();

                    rpt.ReportParameters["Parameter1"].Value = AppointmentID;
                    Telerik.Reporting.InstanceReportSource reportSource = new Telerik.Reporting.InstanceReportSource();
                    reportSource.ReportDocument = rpt;
                    reportViewer1.ReportSource = reportSource;

     

    aspx

    <telerik:ReportViewer
                ID="reportViewer1"
    Width="1300px" Height="900px"             runat="server">
                <ReportSource IdentifierType="TypeReportSource" Identifier="ReportLibrary.ClientApptInvoice, ReportLibrary, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null">
                </ReportSource>
            </telerik:ReportViewer>

  5. Rick
    Admin
    Rick avatar
    5 posts

    Posted 20 Apr Link to this post

    Hi David,

    There are two different ReportViewers that can be used in a WebForms project.
    • The classic ASP.NET Web Forms ReportViewer is a traditional server control with a full server object.
    • The newer HTML5 ReportViewer is a clientside object implemented in JavaScript. We also provide a server-wrapper for this widget for convenience, but it is still a clientside only object under the wrapper. (This seems to be the version you're using.)

    There are several important differences between the two, so I recommend reading the linked articles carefully to choose the best ReportViewer for your application. However, since the HTML5 ReportViewer does not have a server object, you cannot assign an in-memory report to it directly in server code. When working with the HTML5 ReportViewer, you should set your parameter in JavaScript, and refresh the Report. If you're using the server wrapper for the widget, you can set these values in code, and all the JavaScript will be generated for you. Here is an example - which I recommend as a best-practice for new development.

    if (!IsPostBack)
    {
     
        Telerik.ReportViewer.Html5.WebForms.ReportSource typeReportSource = new ReportSource();
     
        typeReportSource.IdentifierType = IdentifierType.TypeReportSource;
        typeReportSource.Identifier = "ClassLibrary1.Report2, ClassLibrary1, Version = 1.0.0.0, Culture = neutral, PublicKeyToken = null";
     
     
        typeReportSource.Parameters.Add("Parameter1", "SetValueHere");
     
        reportViewer1.ReportSource = typeReportSource;
     
    }



    Regards,
    Rick
    Telerik
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
  6. david
    david avatar
    210 posts
    Member since:
    May 2007

    Posted 20 Apr in reply to Rick Link to this post

    Thank you Rick!  This last set of sample code you sent did the trick, might be handy to add to the docs I spent hours looking at them and the forum posts and couldnt find it.

     

    regards

    if (!IsPostBack)
    {

        Telerik.ReportViewer.Html5.WebForms.ReportSource typeReportSource = new ReportSource();

        typeReportSource.IdentifierType = IdentifierType.TypeReportSource;
        typeReportSource.Identifier = "ClassLibrary1.Report2, ClassLibrary1, Version = 1.0.0.0, Culture = neutral, PublicKeyToken = null";


        typeReportSource.Parameters.Add("Parameter1", "SetValueHere");

        reportViewer1.ReportSource = typeReportSource;

    }

Back to Top
DevCraft banner