Quantcast
Channel: SQL Server Reporting Services
Viewing all articles
Browse latest Browse all 1418

Set Reportviewer ReportDataSource to SqlDataSource in code behind and Export to Excel directly?

$
0
0

Set Reportviewer ReportDataSource to SqlDataSource in code behind and Export to Excel directly - can I do this?

-- In my *.aspx page I have 5 drop down lists for filters that have hard coded values or are populated from SqlDatSource select statements.
-- Country, State, Location, Closed Date and Custom Fields:

<asp:DropDownList ID="ddl_Country" AppendDataBoundItems="true" DataSourceID="SqlDataSource_ddl_Country"   DataTextField="Country" DataValueField="Country"   OnSelectedIndexChanged="ddl_Country_SelectedIndexChanged" runat="server" Enabled="true"><asp:listitem text="-- All Countries --" value="MinusOne"></asp:listitem></asp:DropDownList>

<asp:DropDownList ID="ddl_State" AppendDataBoundItems="true" DataSourceID="SqlDataSource_ddl_State" DataTextField="Description" DataValueField="State" runat="server" Enabled="true">                        
<asp:listitem text="-- All States --" value="MinusOne"></asp:listitem></asp:DropDownList>

<asp:DropDownList ID="ddl_LocationDesc" AppendDataBoundItems="true"  DataSourceID="SqlDataSource_ddl_LocationDesc" DataTextField="ClientLocationID" DataValueField="LocationID" Enabled="true"   runat="server">                        
<asp:listitem text="-- All Locations --" value="MinusOne"></asp:listitem></asp:DropDownList>

<asp:DropDownList ID="ddl_OpenClosed" AutoPostBack="false"  runat="server" Enabled="true">                        
<asp:listitem text="Open" Selected="True" value="Open"></asp:listitem>                        
<asp:listitem text="Closed" value="Closed" ></asp:listitem>                        
<asp:listitem text="-- All Open and Closed --" value="MinusOne"></asp:listitem></asp:DropDownList>

<asp:DropDownList ID="ddl_CustomFields" Visible="true" AppendDataBoundItems="true" AutoPostBack="false"                         DataSourceID="SqlDataSource_ddl_CustomFields" DataTextField="FieldDescription" DataValueField="FieldDescription"                         Enabled="true" runat="server">                        
<asp:listitem text="-- All Custom Fields --" value="MinusOne"></asp:listitem></asp:DropDownList>

-- Then a GridView is declared with a SqlDataSource:

<asp:GridView ID="GridView_CustomFieldsList" AllowPaging="False" AllowSorting="True" AutoGenerateColumns="True"             CssClass="CssStyle_GridText" DataSourceID="SqlDataSource_CustomFieldsList" EmptyDataText="-- No records found --"             SortedAscendingHeaderStyle-CssClass="sortasc-header" SortedDescendingHeaderStyle-CssClass="sortdesc-header" runat="server"             width="100%"><PagerSettings position="Top" /></asp:GridView>

-- Then the Data Source for the Grid uses the drop down lists as SelectParameters to filter the rows displayed in the grid

<asp:SqlDataSource ID="SqlDataSource_CustomFieldsList" runat="server">        
<SelectParameters>
            <asp:Parameter Name="Client_Number" Type="String" />
            <asp:ControlParameter ControlID="ddl_Country" Name="parm_CountryID" Type="String" PropertyName="SelectedValue" />              <asp:ControlParameter ControlID="ddl_State" Name="parm_StateID" Type="String" PropertyName="SelectedValue" /> 
             <asp:ControlParameter ControlID="ddl_LocationDesc" Name="parm_LocationID" Type="String"PropertyName="SelectedValue" />  
            <asp:ControlParameter ControlID="ddl_OpenClosed" Name="parm_Date_Closed" Type="String" PropertyName="SelectedValue" />                            
<asp:ControlParameter ControlID="ddl_CustomFields" Name="parm_DefinitionID" Type="String" PropertyName="SelectedValue" />          </SelectParameters>    
</asp:SqlDataSource>

-- All this works fine and allows the user to filter the dataset he requires. 
-- After that I want to take the displayed data in the grid and export it directly to Excel using the ReportViewer and having the
-- SqlDatasource_CustomFieldsList as the source for the ReportDataSource.  Using the code behind and not displaying the
-- report viewer to the end user.
-- Previously I have only defined a dataset in App_Code, linked to and rdlc file and used an *.aspx wrapper page to hold and display
-- the ReportViwer control.
-- Can you guide me in what I need in the code VB behind file to set the Reportviewer ReportDataSource to SqlDataSource in
-- code behind and Export to Excel directly?
-- My thanks ahead of time for your help!

 

 

 


Viewing all articles
Browse latest Browse all 1418

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>