How to pass application values to a local report?

Hello
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>

[15745 byte] By [respag] at [2008-2-7]
# 1

I would have imagined that the following should work for you after you had defined Report parameter in Report->Report Parameters and used it within report to filter data:

protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)
{

Microsoft.Reporting.WebForms.ReportParameter paramIDDisco = new Microsoft.Reporting.WebForms.ReportParameter("IdDisco", DropDownList1.SelectedValue);

ReportViewer1.LocalReport.SetParameters(new Microsoft.Reporting.WebForms.ReportParameter[]{paramIDDisco});

ReportViewer1.LocalReport.Refresh();

}

BUT It probably won't because after postback you might get an exception:

Collection was modified after the enumerator was instantiated. "

It looks like a bug for Beta 2 unless I'm missing something. I count on Rajeev to elaborate a little bit on it.

Regards

Radek


RadekP at 2007-9-9 > top of Msdn Tech,Visual Studio,Visual Studio Report Controls...
# 2
Collection was modified after the enumerator was instantiated.

This message is indeed because of a bug in Beta 2. It has been fixed in June CTP.
RajeevKarunakaran at 2007-9-9 > top of Msdn Tech,Visual Studio,Visual Studio Report Controls...
# 3
Is it a good idea to develop on June CTP? We are releasing the application to the client. The reports at this momemt is not ready to the bugs in VS2005 Beta 2.
SMSMonster at 2007-9-9 > top of Msdn Tech,Visual Studio,Visual Studio Report Controls...

Visual Studio

Site Classified