none
Report Viewer will not dynamically refresh RRS feed

  • Question

  • I have tried everything to fix the issue I am having, and have come up with nothing.  What I have is a ListBox that contains Items that are names of reports to be selected and when the user clicks on an item in the ListBox, it is supposed to change the report in the ReportViewer to what the user selected.  The following is the code definition for the ListBox:

    <

     

    div style="float:left";>
    <asp:ListBox ID="ReportsListBox" runat="server" AutoPostBack="True"
    Height="550px" onselectedindexchanged="ReportsListBox_SelectedIndexChanged"
    Width="200px">
    <asp:ListItem>Hours by Skill</asp:ListItem>
    <asp:ListItem>Hours by WBS</asp:ListItem>
    </asp:ListBox>
    </div>

    Then the definition for the ReportViewer:

    <

     

    rsweb:ReportViewer ID="ReportViewer1" runat="server"
    Font-Names="Verdana" Font-Size="8pt" Height="571px" Width="760px"
    SizeToReportContent="True">
    </rsweb:ReportViewer>

    The C# code to change the Report is as follows:

    string

     

    conString = "Data Source=datasource;Initial Catalog=database;Persist Security Info=True;User ID=userid;Password=password";
    SqlConnection conReport = new SqlConnection(conString);
    SqlCommand cmdReport = new SqlCommand();
    SqlDataReader drReport;
    DataSet DataSetReporting = new dsReporting();
    try
    {
    conReport.Open();
    cmdReport.CommandType =
    CommandType.Text;
    cmdReport.Connection = conReport;
    if (ReportsListBox.SelectedValue.Equals("Hours by Skill"))
    {
    cmdReport.CommandText =
    "SELECT * FROM dbo.table1 WHERE column1 >= @StartingDate and column1 <= @EndingDate AND column2 = @Project AND column3 = @Version ORDER BY column4, column1";
    }
    else if (ReportsListBox.SelectedValue.Equals("Hours by WBS"))
    {
    cmdReport.CommandText =
    "SELECT * FROM dbo.table1 WHERE column1 >= @StartingDate and column1 <= @EndingDate AND column2 = @Project AND column3 = @Version ORDER BY column4, column1";
    }
    if (ReportsListBox.SelectedValue.Equals("Hours by Skill"))
    {
    ReportViewer1.LocalReport.ReportPath =
    "HoursSkill.rdlc";
    }
    else if (ReportsListBox.SelectedValue.Equals("Hours by WBS"))
    {
    ReportViewer1.LocalReport.ReportPath =
    "HoursWBS.rdlc";
    }
    ReportDataSource rds = new ReportDataSource();
    rds.Name =
    "dsReporting_dtHoursbySkill";
    rds.Value = DataSetReporting.Tables[0];
    ReportViewer1.LocalReport.DataSources.Clear();
    ReportViewer1.LocalReport.DataSources.Add(rds);
    ReportViewer1.LocalReport.Refresh();
    ReportViewer1.DataBind();

    I have literally looked everywhere and done everything I can to try and make it work, but it never does

    Friday, December 3, 2010 6:36 PM

Answers

  • Changing the viewer is another way to do it, but it's unnecessary. Did you take a look at the linked sample code already? Namely, the SupplyingData sample shows how to change reports from a list selection and how to hook up data to them.

    Suggestion: when you include your code, it's helpful to at least show which method it comes from, and replace sensitive code with ... I did find it hard to make sense of your code without the context.


    Cephas Lin This posting is provided "AS IS" with no warranties.
    • Marked as answer by Jonathan Du Monday, December 6, 2010 8:36 PM
    Monday, December 6, 2010 5:49 PM
    Moderator

All replies

  • Have you looked at the samples at http://code.msdn.microsoft.com/reportviewer? There's one there that speaks to your scenario.
    Cephas Lin This posting is provided "AS IS" with no warranties.
    Friday, December 3, 2010 7:12 PM
    Moderator
  • The parameters for the report refresh just fine. I have AutoPostBack set to true for every element. It is almost like the new report is not rendering to the page somehow
    Monday, December 6, 2010 4:48 PM
  • I'm not sure what you mean by "The parameters for the report refresh just fine." You do not have any code that refreshes report parameters.

    What I also see in your code is that the SQL command is never executed, even though the SQL connection is opened. Also, not sure what DataSetReporting is. If that's your DataSet definition, then what you have now is essentially binding an empty table to your report. When you walk through your debugging, you need to first make sure that your live data is properly retrieved before it's used in a ReportDataSource object. Try debugging the sample code from the link I sent you and walk through the code to see the data properly retrieved in the debugger.


    Cephas Lin This posting is provided "AS IS" with no warranties.
    Monday, December 6, 2010 5:09 PM
    Moderator
  • I need to make some corrections.  What I originally posted is not the entire code as there is network sensitive code included in other parts of the code.  The definition for the DataSetReporting is:

    DataSet

     

    DataSetReporting = new dsReporting();

    The SQL statement is executed with the following lines:

    cmdReport.Parameters[

    "@Project"].Value = projectname;

    cmdReport.Parameters[

    "@Version"].Value = versionname;

    drReport = cmdReport.ExecuteReader();

    DataSetReporting.Tables[0].Load(drReport);

    drReport.Close();

    conReport.Close();

    I saw some code on a related post on this topic in a different thread.  I was wondering if the following code may help me in my situation:

    ControlCollection coll = oldViewer.Parent.Controls;
    int oldIndex = coll.IndexOf(oldViewer);
    ReportViewer newViewer = new ReportViewer();
    coll.AddAt(oldIndex, newViewer);
    coll.Remove(oldViewer);

    Monday, December 6, 2010 5:31 PM
  • Changing the viewer is another way to do it, but it's unnecessary. Did you take a look at the linked sample code already? Namely, the SupplyingData sample shows how to change reports from a list selection and how to hook up data to them.

    Suggestion: when you include your code, it's helpful to at least show which method it comes from, and replace sensitive code with ... I did find it hard to make sense of your code without the context.


    Cephas Lin This posting is provided "AS IS" with no warranties.
    • Marked as answer by Jonathan Du Monday, December 6, 2010 8:36 PM
    Monday, December 6, 2010 5:49 PM
    Moderator
  • This did the trick.  I thank you VERY much!  I apologize for not being more clear from the start with my original post.  And I will place "..." in place of my sensitive network information in the future.
    Monday, December 6, 2010 8:38 PM
  • You are very welcome!
    Cephas Lin This posting is provided "AS IS" with no warranties.
    Monday, December 6, 2010 8:40 PM
    Moderator