Solved

Why is my export not working when I try to export data from TELERIK RADGRID to EXCEL?

Posted on 2011-10-30
4
1,630 Views
Last Modified: 2013-11-25
I trying to export data in TELERIK RADRGID to EXCEL SPREADSHEET on button click.
I tried below code but it not showing the OPEN window for me to SAVE/OPEN the excel sheet.
Below is my code.
ASPX CODE:
----------
<telerik:RadGrid AllowPaging="true" ID="grdQueues" runat="server" OnSelectedIndexChanged="grd_SelectedIndexChanged"  
                        ShowStatusBar="true" AllowSorting="true" PageSize="10" AutoGenerateColumns="false" 
                        OnPageIndexChanged="grd_PageIndexChanged" OnNeedDataSource="grd_NeedDataSource"
                        Width="100%" Visible="false" OnExcelMLExportStylesCreated="grd_ExcelMLExportStylesCreated"
                        OnExcelMLExportRowCreated="grd_ExcelMLExportRowCreated">             
                    <PagerStyle AlwaysVisible="true" Mode="NextPrevAndNumeric" PagerTextFormat="Change page: {4} | Displaying page {0} of {1} |, items {2} to {3} of {5}." />
                    <ClientSettings EnableRowHoverStyle="true" EnablePostBackOnRowClick="true">
                        <Selecting AllowRowSelect="true" />
                        <Scrolling AllowScroll="true" UseStaticHeaders="true" />                        
                    </ClientSettings>
                    <MasterTableView ShowHeadersWhenNoRecords="true" EditMode="PopUp">      
                        <NoRecordsTemplate><div align="center">
                                No Records to Display
                            </div>
                        </NoRecordsTemplate>
                        <Columns>
                            <telerik:GridTemplateColumn HeaderText="Acct Nbr">
                                <ItemTemplate>
                                    <asp:Label ID="lblNbr" ClientIDMode="Static" runat="server" Text='<%# Bind("NBR") %>'></asp:Label>
                                </ItemTemplate>
                                <ItemStyle HorizontalAlign="Center" />
                                    <HeaderStyle HorizontalAlign="Center" Font-Bold="true" />
                            </telerik:GridTemplateColumn>
                            <telerik:GridTemplateColumn HeaderText="Customer Name">
                                <ItemTemplate>
                                    <asp:Label ID="lblName" ClientIDMode="Static" runat="server" Text='<%# Bind("NAME") %>'></asp:Label>
                                </ItemTemplate>
                                <ItemStyle HorizontalAlign="Center" />
                                    <HeaderStyle HorizontalAlign="Center" Font-Bold="true" />
                            </telerik:GridTemplateColumn>                            
                        </Columns>                       
                    </MasterTableView>                      
                    </telerik:RadGrid>

--------------------------
ASPX.CS CODE
-----------------------------
protected void btnExport_Click(object sender, EventArgs e)
        {
            grd.ExportSettings.ExportOnlyData = true;
            grd.ExportSettings.IgnorePaging = true;
            grd.ExportSettings.OpenInNewWindow = true;
            grd.MasterTableView.ExportToExcel();
        }

        protected void grd_ExcelMLExportRowCreated(object source, Telerik.Web.UI.GridExcelBuilder.GridExportExcelMLRowCreatedArgs e)
        {
            if (e.RowType == Telerik.Web.UI.GridExcelBuilder.GridExportExcelMLRowType.DataRow)
            {
                if (e.Row.Cells[0] != null && ((string)e.Row.Cells[0].Data.DataItem).Contains("U"))
                {
                    e.Row.Cells[0].StyleValue = "MyCustomStyle";
                }
            }
        }

        protected void grd_ExcelMLExportStylesCreated(object source, Telerik.Web.UI.GridExcelBuilder.GridExportExcelMLStyleCreatedArgs e)
        {
            foreach (Telerik.Web.UI.GridExcelBuilder.StyleElement style in e.Styles)
            {
                if (style.Id == "headerStyle")
                {
                    style.FontStyle.Bold = true;
                    style.FontStyle.Color = System.Drawing.Color.Gainsboro;
                    style.InteriorStyle.Color = System.Drawing.Color.Wheat;
                    style.InteriorStyle.Pattern = Telerik.Web.UI.GridExcelBuilder.InteriorPatternType.Solid;
                }
                else if (style.Id == "itemStyle")
                {
                    style.InteriorStyle.Color = System.Drawing.Color.WhiteSmoke;
                    style.InteriorStyle.Pattern = Telerik.Web.UI.GridExcelBuilder.InteriorPatternType.Solid;
                }
                else if (style.Id == "alternatingItemStyle")
                {
                    style.InteriorStyle.Color = System.Drawing.Color.LightGray;
                    style.InteriorStyle.Pattern = Telerik.Web.UI.GridExcelBuilder.InteriorPatternType.Solid;
                }
            }

            Telerik.Web.UI.GridExcelBuilder.StyleElement myStyle = new Telerik.Web.UI.GridExcelBuilder.StyleElement("MyCustomStyle");
            myStyle.FontStyle.Bold = true;
            myStyle.FontStyle.Italic = true;
            myStyle.InteriorStyle.Color = System.Drawing.Color.Gray;
            myStyle.InteriorStyle.Pattern = Telerik.Web.UI.GridExcelBuilder.InteriorPatternType.Solid;
            e.Styles.Add(myStyle);
        }

Open in new window

0
Comment
Question by:beginner_help
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
4 Comments
 

Author Comment

by:beginner_help
ID: 37063036
Someone please help me with this
0
 
LVL 33

Accepted Solution

by:
Norie earned 500 total points
ID: 37090518
Doesn't setting OpenInNewWindow to true open the export in a browser window rather than actually exporting it to an Excel file?
0

Featured Post

Secure Your Active Directory - April 20, 2017

Active Directory plays a critical role in your company’s IT infrastructure and keeping it secure in today’s hacker-infested world is a must.
Microsoft published 300+ pages of guidance, but who has the time, money, and resources to implement? Register now to find an easier way.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Excel can be a tricky bit of software to get your head around. Whilst you’ll be able to eventually get to grips with the basic understanding of how to get by, there are a few Excel tips that not everybody will even know about let alone know how to d…
Do you use a spreadsheet like Microsoft's Excel?  Have you ever wanted to link out to a non excel file on your computer or network drive?  This is the way I found to do it!
This Micro Tutorial will demonstrate in Microsoft Excel how to add style and sexy appeal to horizontal bar charts.
This Micro Tutorial demonstrates in Microsoft Excel how to consolidate your marketing data by creating an interactive charts using form controls. This creates cool drop-downs for viewers of your chart to choose from.

730 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question