This is a migrated thread and some comments may be shown as answers.

Exporting RadGrid to Excel Error

6 Answers 107 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Ryan Pope
Top achievements
Rank 1
Ryan Pope asked on 10 Aug 2010, 02:09 PM
I am trying to export the data from my RadGrid and keep recieving this error:

The DataSourceID of 'grdShipToCodes' must be the ID of a control of type IDataSource.  A control with ID 'dsShipToCodes' could not be found.


Is there anyway that I can exclude the column that contains this control on my export?

My Radgrid Code is below:
<telerik:RadGrid ID="grdDistrictGrowthCustomer" runat="server" 
    DataSourceID="SqlDataSource1" GridLines="None" AllowPaging="True" 
    AutoGenerateColumns="False" PageSize="100" EnableLinqExpressions="False" 
    AllowFilteringByColumn="True" AllowSorting="True">
    <ExportSettings IgnorePaging="True" OpenInNewWindow="True">
    </ExportSettings>
    <ClientSettings EnableRowHoverStyle="True">
    </ClientSettings>
    <MasterTableView DataSourceID="SqlDataSource1" ClientDataKeyNames="CustNo" CommandItemDisplay="Top"                                
        NoMasterRecordsText="There are no growth account customers in this district.">
        <CommandItemSettings 
            ShowAddNewRecordButton="False" ShowRefreshButton="False" />
        <RowIndicatorColumn>
            <HeaderStyle Width="20px" />
        </RowIndicatorColumn>
        <ExpandCollapseColumn>
            <HeaderStyle Width="20px" />
        </ExpandCollapseColumn>
        <Columns>
            <telerik:GridTemplateColumn DataField="CustNo" HeaderText="No." 
                UniqueName="CustNo" AutoPostBackOnFilter="True" 
                CurrentFilterFunction="Contains" 
                FilterControlAltText="Type Number filter and press ENTER." 
                FilterControlWidth="55px" ShowFilterIcon="False" SortExpression="CustNo">
                <ItemTemplate>
                    <asp:Label ID="lblCustNo" runat="server" Text='<%# Eval("CustNo") %>'></asp:Label>
                </ItemTemplate>
                <HeaderStyle Font-Bold="True" Font-Italic="False" Font-Overline="False" 
                    Font-Strikeout="False" Font-Underline="False" Width="100px" Wrap="True" />
            </telerik:GridTemplateColumn>
            <telerik:GridBoundColumn DataField="CustName" HeaderText="Name" 
                UniqueName="CustName" AndCurrentFilterFunction="Contains" 
                AutoPostBackOnFilter="True" 
                FilterControlAltText="Type Name filter and press ENTER." 
                FilterControlWidth="110px" ShowFilterIcon="False" SortExpression="CustName">
                <HeaderStyle Font-Bold="True" Font-Italic="False" Font-Overline="False" 
                    Font-Strikeout="False" Font-Underline="False" Width="175px" Wrap="True" />
            </telerik:GridBoundColumn>
            <telerik:GridBoundColumn DataField="CustContact" HeaderText="Contact" 
                UniqueName="CustContact" AndCurrentFilterFunction="Contains" 
                AutoPostBackOnFilter="True" 
                FilterControlAltText="Type Contact filter and press ENTER." 
                FilterControlWidth="90px" ShowFilterIcon="False" SortExpression="CustContact">
                <HeaderStyle Font-Bold="True" Font-Italic="False" Font-Overline="False" 
                    Font-Strikeout="False" Font-Underline="False" Width="140px" Wrap="True" />
            </telerik:GridBoundColumn>
            <telerik:GridBoundColumn DataField="CustAddress" HeaderText="Address" 
                UniqueName="CustAddress" AllowFiltering="False" 
                SortExpression="CustAddress">
                <HeaderStyle Font-Bold="True" Font-Italic="False" Font-Overline="False" 
                    Font-Strikeout="False" Font-Underline="False" Wrap="True" />
            </telerik:GridBoundColumn>
            <telerik:GridBoundColumn DataField="CustCity" HeaderText="City" 
                UniqueName="CustCity" AndCurrentFilterFunction="Contains" 
                AutoPostBackOnFilter="True" 
                FilterControlAltText="Type City filter and press ENTER." 
                FilterControlWidth="70px" ShowFilterIcon="False" SortExpression="CustCity">
                <HeaderStyle Font-Bold="True" Font-Italic="False" Font-Overline="False" 
                    Font-Strikeout="False" Font-Underline="False" Width="140px" Wrap="True" />
            </telerik:GridBoundColumn>
            <telerik:GridBoundColumn DataField="CustState" HeaderText="State" 
                UniqueName="CustState" AndCurrentFilterFunction="Contains" 
                AutoPostBackOnFilter="True" 
                FilterControlAltText="Type State filter and press ENTER." 
                FilterControlWidth="25px" ShowFilterIcon="False" SortExpression="CustState">
                <HeaderStyle Font-Bold="True" Font-Italic="False" Font-Overline="False" 
                    Font-Strikeout="False" Font-Underline="False" Width="40px" Wrap="True" />
            </telerik:GridBoundColumn>
            <telerik:GridBoundColumn DataField="CustPostCode" HeaderText="Zip" 
                UniqueName="CustPostCode" AndCurrentFilterFunction="Contains" 
                AutoPostBackOnFilter="True" 
                FilterControlAltText="Type Zip filter and press ENTER." 
                FilterControlWidth="35px" ShowFilterIcon="False" SortExpression="CustPostCode">
                <HeaderStyle Font-Bold="True" Font-Italic="False" Font-Overline="False" 
                    Font-Strikeout="False" Font-Underline="False" Width="65px" Wrap="True" />
            </telerik:GridBoundColumn>
            <telerik:GridTemplateColumn HeaderText="Ship-to Code" UniqueName="ShipToCodes" 
                AllowFiltering="False" Groupable="False" ShowSortIcon="False">
                <ItemTemplate>
                    <asp:Label ID="lblCustomerNo" runat="server" Text='<%# Eval("CustNo") %>' Visible="False"></asp:Label>
                    <asp:SqlDataSource ID="dsShipToCodes" runat="server" 
                        ConnectionString="<%$ ConnectionStrings:RDAConnectionString %>" 
                        SelectCommand="pr_GCP_Find_ShipTo_Codes_By_RDA_District_And_Customer" 
                        SelectCommandType="StoredProcedure">
                        <SelectParameters>
                            <asp:Parameter DefaultValue="INC" Name="Company" Type="String" />
                            <asp:ControlParameter ControlID="cboDistricts" DefaultValue="" Name="District" 
                                PropertyName="SelectedItem.Text" Type="String" />
                            <asp:ControlParameter ControlID="lblCustomerNo" Name="CustomerNo" PropertyName="Text" 
                                Type="String" />
                        </SelectParameters>
                    </asp:SqlDataSource>
                    <asp:GridView ID="grdShipToCodes" runat="server" DataSourceID="dsShipToCodes" 
                        AutoGenerateColumns="False" GridLines="None" ShowHeader="False">
                        <Columns>
                            <asp:TemplateField>
                                <ItemTemplate>
                                    <div style="cursor: pointer"><asp:Label ID="lblShipToCode" runat="server" Text='<%# Bind("STA_Code") %>' Font-Underline="True" Font-Size="Small"></asp:Label></div>
                                    <asp:Label ID="lblName" runat="server" Text='<%# Bind("STA_Name") %>' Visible="false"></asp:Label>
                                    <asp:Label ID="lblAddress" runat="server" Text='<%# Bind("STA_Address") %>' Visible="false"></asp:Label>
                                    <asp:Label ID="lblAddress2" runat="server" Text='<%# Bind("STA_Address2") %>' Visible="false"></asp:Label>
                                    <asp:Label ID="lblCity" runat="server" Text='<%# Bind("STA_City") %>' Visible="false"></asp:Label>
                                    <asp:Label ID="lblState" runat="server" Text='<%# Bind("STA_State") %>' Visible="false"></asp:Label>
                                    <asp:Label ID="lblPostCode" runat="server" Text='<%# Bind("STA_PostCode") %>' Visible="false"></asp:Label>
                                    <asp:Label ID="lblPhoneNo" runat="server" Text='<%# Bind("STA_PhoneNo") %>' Visible="false"></asp:Label>
                                </ItemTemplate>
                            </asp:TemplateField>
                        </Columns>
                    </asp:GridView>
                </ItemTemplate>
                <HeaderStyle Font-Bold="True" Font-Italic="False" Font-Overline="False" 
                    Font-Strikeout="False" Font-Underline="False" Width="100px" Wrap="True" />
            </telerik:GridTemplateColumn>
            <telerik:GridTemplateColumn HeaderText="Linked Custs." UniqueName="LinkedCust" 
                AllowFiltering="False" Groupable="False" ShowSortIcon="False">
                <ItemTemplate>
                    <asp:SqlDataSource ID="dsLinkedCustomers" runat="server" 
                        ConnectionString="<%$ ConnectionStrings:RDAConnectionString %>" 
                        SelectCommand="pr_GCP_Find_All_Linked_Customers" 
                        SelectCommandType="StoredProcedure">
                        <SelectParameters>
                            <asp:Parameter DefaultValue="INC" Name="Company" Type="String" />
                            <asp:ControlParameter ControlID="lblCustomerNo" Name="CustomerNo" PropertyName="Text" 
                                Type="String" />
                        </SelectParameters>
                    </asp:SqlDataSource>
                    <asp:GridView ID="grdLinkedCustomers" runat="server" DataSourceID="dsLinkedCustomers" 
                        AutoGenerateColumns="False" GridLines="None" ShowHeader="False" 
                        EnableModelValidation="True">
                    </asp:GridView>
                </ItemTemplate>
                <HeaderStyle Font-Bold="True" Font-Italic="False" Font-Overline="False" 
                    Font-Strikeout="False" Font-Underline="False" Width="90px" Wrap="True" />
                <ItemStyle Font-Bold="False" Font-Italic="False" Font-Overline="False" 
                    Font-Strikeout="False" Font-Underline="False" HorizontalAlign="Left" 
                    Wrap="True" />
            </telerik:GridTemplateColumn>
            <telerik:GridBoundColumn DataField="BlockType" HeaderText="Blocked" 
                UniqueName="BlockType" AllowFiltering="False" 
                SortExpression="BlockType">
                <HeaderStyle Font-Bold="True" Font-Italic="False" Font-Overline="False" 
                    Font-Strikeout="False" Font-Underline="False" Wrap="True" />
            </telerik:GridBoundColumn>
            <telerik:GridTemplateColumn UniqueName="Select" HeaderText="Action" 
                Groupable="False" ShowFilterIcon="False" ShowSortIcon="False">
                <ItemTemplate>
                    <asp:LinkButton ID="btnRequestPromotion" CommandName="RequestPromotion" runat="server" Visible="false">Request Promotion</asp:LinkButton>
                    <asp:LinkButton ID="btnApprovePromotion" CommandName="ApprovePromotion" runat="server" Visible="false">Approve & Promote</asp:LinkButton>
                </ItemTemplate>
                <FilterTemplate>
                    <asp:Button ID="btnApplyFilters" runat="server" CommandName="ApplyFilter" Height="22px" Text="Apply Filters" ToolTip="Click to apply enetered filters, or press enter while in a filter texbox." Width="115px" />                                                    
                </FilterTemplate>
                <HeaderStyle Width="125px" Font-Bold="True" Font-Italic="False" 
                    Font-Overline="False" HorizontalAlign="Center" Font-Strikeout="False" Font-Underline="False" 
                    Wrap="True" />
                <ItemStyle Font-Bold="False" Font-Italic="False" Font-Overline="False" 
                    Font-Strikeout="False" Font-Underline="False" HorizontalAlign="Center" 
                    Wrap="True" />
            </telerik:GridTemplateColumn>
        </Columns>
        <ItemStyle Font-Bold="False" Font-Italic="False" Font-Overline="False" 
            Font-Strikeout="False" Font-Underline="False" VerticalAlign="Top" Wrap="True" />
        <AlternatingItemStyle Font-Bold="False" Font-Italic="False" 
            Font-Overline="False" Font-Strikeout="False" Font-Underline="False" 
            VerticalAlign="Top" Wrap="True" />
    </MasterTableView>
</telerik:RadGrid>

6 Answers, 1 is accepted

Sort by
0
Daniel
Telerik team
answered on 10 Aug 2010, 03:22 PM
Hello Ryan,

Please try to wrap the GridView and the datasource control in ASP Panel.
<asp:Panel ID="Panel1" runat="server">
    <asp:SqlDataSource ...
    <asp:GridView ...
</asp:Panel>

I hope this helps.

Regards,
Daniel
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
0
Ryan Pope
Top achievements
Rank 1
answered on 10 Aug 2010, 04:04 PM

I need to show this section during viewing, but need it to not be exported. How do I hide the panel when I click the export button.

 

 

Protected Sub btnExportToExcel_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnExportToExcel.Click
  
grdDistrictGrowthCustomer.ExportSettings.IgnorePaging = True
  
grdDistrictGrowthCustomer.ExportSettings.OpenInNewWindow = True
  
grdDistrictGrowthCustomer.MasterTableView.ExportToExcel()
  
End Sub

0
Daniel
Telerik team
answered on 10 Aug 2010, 04:24 PM
Hello Ryan,

The easiest way would be to set ExportSettings-ExportOnlyData="true".

Alternatively you could hide the column manually:
    ...
    RadGrid1.MasterTableView.GetColumn("ShipToCodes").Visible = false;
    RadGrid1.MasterTableView.ExportToExcel();
}

I hope this helps.

Regards,
Daniel
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
0
Ryan Pope
Top achievements
Rank 1
answered on 10 Aug 2010, 04:36 PM
I am still getting an errow with the below code:
Protected Sub btnExportToExcel_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnExportToExcel.Click
    grdDistrictGrowthCustomer.ExportSettings.ExportOnlyData = True
    grdDistrictGrowthCustomer.MasterTableView.GetColumn("ShipToCodes").Visible = False
    grdDistrictGrowthCustomer.MasterTableView.ExportToExcel()
End Sub


the error is:
The DataSourceID of 'grdLinkedCustomers' must be the ID of a control of type IDataSource.  A control with ID 'dsLinkedCustomers' could not be found.
0
Ryan Pope
Top achievements
Rank 1
answered on 13 Aug 2010, 03:28 PM
??????
0
Daniel
Telerik team
answered on 16 Aug 2010, 05:06 PM
Hello Ryan,

Unfortunately I'm unable to reproduce the problem on my end. Please download the attached demo and let me know how to modify it so that I can replicate the issue.

Regards,
Daniel
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
Tags
Grid
Asked by
Ryan Pope
Top achievements
Rank 1
Answers by
Daniel
Telerik team
Ryan Pope
Top achievements
Rank 1
Share this question
or