How to pass application values to a local report?

respag

New member
Joined
Jul 2, 2005
Messages
1
Programming Experience
10+
Hello
I have created (using Visual Studio 2005 Beta 2) 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 sentence ReportViewer1.LocalReport.Refresh()
in the DropDownList1_SelectedIndexChanged, without success.
Please, could you help me?
Thank in advance

Here my code:
<%@PageLanguage="VB" %>
<%
@RegisterAssembly="Microsoft.ReportViewer.WebForms, Version=8.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"
Namespace="Microsoft.Reporting.WebForms"TagPrefix="rsweb" %>
<!DOCTYPE html PUBLIC"-//W3C//DTD XHTML 1.1//EN""http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<
script runat="server">
ProtectedSub DropDownList1_SelectedIndexChanged(ByVal sender AsObject, ByVal e As System.EventArgs)
ReportViewer1.LocalReport.Refresh()
EndSub

</script>
<html xmlns="http://www.w3.org/1999/xhtml">
<
head runat="server">
<title>Untitled Page</title>
</
head>
<
body>
<form id="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:ReportViewer ID="ReportViewer1" runat="server" Font-Names="Verdana" Font-Size="8pt" Height="400px" Width="400px">
<LocalReport DisplayName="Report" ReportPath="Report.rdlc">
<DataSources>
<rsweb:ReportDataSource DataSourceId="ObjectDataSource1" Name="DataSet1_Discos"/>
</DataSources>
</LocalReport>
</rsweb:ReportViewer>

<
asp:ObjectDataSource ID="ObjectDataSource1" runat="server" SelectMethod="GetData" TypeName="MisDvdsTableAdapters.DiscosTableAdapter">
<SelectParameters>
<asp:ControlParameter ControlID="DropDownList1" Name="IdDisco" PropertyName="SelectedValue" Type="Int32" DefaultValue=""/>
</SelectParameters>
</asp:ObjectDataSource>

<
asp:GridView ID="GridView1" runat="server" CellPadding="4" DataSourceID="ObjectDataSource1" ForeColor="#333333" GridLines="None">
<FooterStyle BackColor="#990000" Font-Bold="True" ForeColor="White"/>
<RowStyle BackColor="#FFFBD6" ForeColor="#333333"/>
<PagerStyle BackColor="#FFCC66" ForeColor="#333333" HorizontalAlign="Center"/>
<SelectedRowStyle BackColor="#FFCC66" Font-Bold="True" ForeColor="Navy"/>
<HeaderStyle BackColor="#990000" Font-Bold="True" ForeColor="White"/>
<AlternatingRowStyleBackColor="White"/>
</asp:GridView>
</div>
</form>
</
body>
</
html>
 
Last edited:

Latest posts

Back
Top