How to pass application values to a local report?
I have created a simple web application that uses the new ReportViewer control with a local report. The application has a DropDownList and I want that when I select an item in the combo, the report changes according the value selected. The report use a DataSet with an select parametrized query:
SELECT *
FROM Discos
WHERE (IdDisco = @IdDisco)
When I add the ReportViewer control to the web form, I get a ObjectDataSource that I use as the data source of the ReportViewer.
When I run the application, it works. The reportviewer returns the information for the ID=1. If I change the inicial selected item in the dropdownlist, for example to the third value and run the application again, now I get the information for the ID=3. So far, so good. But when I change the selection, in runtime , the report don′t change.
Though, as you can see in the code below, I have added a DataGrid that use the same datasource and it always shows the correct information, while the reportviewer keep showing the initial information.
I tried to add the sentenceReportViewer1.LocalReport.Refresh();
in theDropDownList1_SelectedIndexChanged, without success.
Please, could you help me?
Thank in advance
Here my code:
<%@PageLanguage="C#" %>
<%@RegisterAssembly="Microsoft.ReportViewer.WebForms, Version=8.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"
Namespace="Microsoft.Reporting.WebForms"TagPrefix="rsweb" %>
<!DOCTYPEhtmlPUBLIC"-//W3C//DTD XHTML 1.1//EN""http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<scriptrunat="server">
protectedvoid DropDownList1_SelectedIndexChanged(
object sender,EventArgs e)
{
ReportViewer1.LocalReport.Refresh();
}
</script>
<htmlxmlns="http://www.w3.org/1999/xhtml">
<headrunat="server">
<title>Untitled Page</title>
</head>
<body>
<formid="form1"runat="server">
<div>
Select an ID:
<asp:DropDownListID="DropDownList1"runat="server"AutoPostBack="True"OnSelectedIndexChanged="DropDownList1_SelectedIndexChanged">
<asp:ListItem>1</asp:ListItem>
<asp:ListItem>2</asp:ListItem>
<asp:ListItem>3</asp:ListItem>
</asp:DropDownList>
<br/><rsweb:ReportViewerID="ReportViewer1"runat="server"Font-Names="Verdana"Font-Size="8pt"Height="400px"Width="400px">
<LocalReportDisplayName="Report"ReportPath="Report.rdlc">
<DataSources>
<rsweb:ReportDataSourceDataSourceId="ObjectDataSource1"Name="DataSet1_Discos"/>
</DataSources>
</LocalReport>
</rsweb:ReportViewer>
<asp:ObjectDataSourceID="ObjectDataSource1"runat="server"SelectMethod="GetData"TypeName="MisDvdsTableAdapters.DiscosTableAdapter">
<SelectParameters>
<asp:ControlParameterControlID="DropDownList1"Name="IdDisco"PropertyName="SelectedValue"Type="Int32"DefaultValue=""/>
</SelectParameters>
</asp:ObjectDataSource>
<asp:GridViewID="GridView1"runat="server"CellPadding="4"DataSourceID="ObjectDataSource1"ForeColor="#333333"GridLines="None">
<FooterStyleBackColor="#990000"Font-Bold="True"ForeColor="White"/>
<RowStyleBackColor="#FFFBD6"ForeColor="#333333"/>
<PagerStyleBackColor="#FFCC66"ForeColor="#333333"HorizontalAlign="Center"/>
<SelectedRowStyleBackColor="#FFCC66"Font-Bold="True"ForeColor="Navy"/>
<HeaderStyleBackColor="#990000"Font-Bold="True"ForeColor="White"/>
<AlternatingRowStyleBackColor="White"/>
</asp:GridView>
</div>
</form>
</body>
</html>

