locked
ASP.Net Report Viewer Control RRS feed

  • Question

  • User-808020646 posted

    I found a sample of a local report that uses a prameterized query. However,  this example is using a drop down list control outside of the report viewer control to set the value for the parameter. My question is I thought the report viewer provided functionality of this sort.  Thanks !!!

    Thursday, May 24, 2012 3:14 PM

Answers

  • User1242141900 posted

    Sure! In my case, I have a page with five gridviews and for each gridview I have linkButton "View Graphs". Then, when the user clicks on this link, the graphs page is opened passing the parameters in the query. So, in my default page I have the following:

    <asp:LinkButton ID="ViewGraphsButton" runat="server" Text="View Graphs" OnClientClick="javascript:window.open('MyGraphsPage.aspx?ID=1&Year=' + document.getElementById('FiscalYearDDL').options[document.getElementById('FiscalYearDDL').selectedIndex].value, '_blank'); return false;" />

    I define the ID parameter based on which linkButton was clicked and the Year parameter I'm getting from a dropdownlist. Then in my graphs page, I just get this parameters back using the code I posted earlier. So, the same way I got the year from a ddl, you can get it from any other control.

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Tuesday, May 29, 2012 11:31 AM

All replies

  • User1242141900 posted

    Sorry, but I didn't get your question. Do you wanna know how to det the control as a parameter? If so, what you have to do is, in the aspx page that contains the report, click on the arrow besides your datasort and select "Configure Data Source...". Then, when you get to "Define Parameter" you can select different parameter sources: it can be a query string, for example, retrieved from the url, but it can also be a control, such as a drop down list.

    I hope I have answered your question, but if not, feel free to post more details on what you need to know :)

    Thursday, May 24, 2012 6:02 PM
  • User2105670541 posted

    You can pass the parameter from the reportviewer using ReportParameters array or you can also call a report based on the querystring and process it further like below:

    http://localhost/reportserver?%2fFolder%2fMyReport&rs:Command=Render&YourParameterCountry=India&YourParameterState=Delhi

    now you just use this url to process your request, and you can always set the value for those querystring from your any other control.

     

    Friday, May 25, 2012 1:24 AM
  • User-808020646 posted

    Thanks Guy's. But all I was asking is if I wanted to use a stored procedure with parameters how would I implement that? I was under the impression that the viewer control works to where it knows that you are using a stored procedure with parameters? Thanks !!!

    Friday, May 25, 2012 11:10 AM
  • User627829463 posted

    I create some reports earlier this week, none of them have parameter. I call the stored procedure with parameter and which will return a dataset. then I assign the dataset to the reportviewer. I don't have to pass any parameter to the reportviewer. only to the stored procedure.

    Friday, May 25, 2012 4:34 PM
  • User1242141900 posted

    For the report I created recently, I have created a dataset file, where I included about 6 datatables I was going to need for the reports. Then, in my reports, I created about 8 graphs, where I used the datatables from the dataset file as the datasource. In addition, above each graph, I have created a textbox, which gets the title of the graph from the database. So, the value of my textbox was something like this:

    =First(Fields!MyParameter.Value, "MyDataSetFile_MyDataTableInTheDataSetFile")

    Worked like a charm! As for the parameters for the report, I have created a page graphsViewer, where I added a local report with my rdlc file as the reportPath. Finally, in the code behind of GraphsViewer, I added the following to my Page_Load event:

    param1 = Request.QueryString("paramName1")
    param2 = Request.QueryString("paramName2")
    
    MyReportViewer.LocalReport.Refresh()
    MyReportViewer.DataBind()

    Of course, I'm ommiting a some details, but I guess you can have an idea of how to implement it. Hope it helps :)

    Friday, May 25, 2012 4:50 PM
  • User-808020646 posted

    Thanks !!! Do you mind showing me how you implemented this. I mean where does the user select the value to send to the stored procedure?

    Tuesday, May 29, 2012 11:04 AM
  • User1242141900 posted

    Sure! In my case, I have a page with five gridviews and for each gridview I have linkButton "View Graphs". Then, when the user clicks on this link, the graphs page is opened passing the parameters in the query. So, in my default page I have the following:

    <asp:LinkButton ID="ViewGraphsButton" runat="server" Text="View Graphs" OnClientClick="javascript:window.open('MyGraphsPage.aspx?ID=1&Year=' + document.getElementById('FiscalYearDDL').options[document.getElementById('FiscalYearDDL').selectedIndex].value, '_blank'); return false;" />

    I define the ID parameter based on which linkButton was clicked and the Year parameter I'm getting from a dropdownlist. Then in my graphs page, I just get this parameters back using the code I posted earlier. So, the same way I got the year from a ddl, you can get it from any other control.

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Tuesday, May 29, 2012 11:31 AM