I have seen demo of radgrid export to excel. but when I try to use this feature. I could not find it working for me. Grid shows the export button on commend item display but when I press that button page gets refreshed but there is no export behavior. Can anybody help me out on this issue?
Thanks.
Thanks.
13 Answers, 1 is accepted
0

Princy
Top achievements
Rank 2
answered on 21 Nov 2012, 07:54 AM
Hi,
I suppose you have ajaxified your grid. The exporting feature of the control work with regular postbacks only. Once the grid is ajaxified, it should be cancelled before exporting.
JS:
Also check the following help documentation which explains more about this.
Export from Ajaxified Grid
Thanks,
Princy.
I suppose you have ajaxified your grid. The exporting feature of the control work with regular postbacks only. Once the grid is ajaxified, it should be cancelled before exporting.
JS:
function
onRequestStart(sender, args) {
if
(args.get_eventTarget().indexOf(
"ExportToExcelButton"
) >= 0)
args.set_enableAjax(
false
);
}
Export from Ajaxified Grid
Thanks,
Princy.
0

Sheeraz
Top achievements
Rank 1
answered on 21 Nov 2012, 01:47 PM
Thanks for your response Princy.
But its not working, I am actually using command buttons of RadGrid. I have tried to use this script as I have ajaxified my grid.
I have programmatically binded DataSource to this grid. When I click on the export button on top of grid. Page gets refreshed but there is no export behavior shown by RadGrid.
If you have seen such scenario, please tell me the way out.
Regards.
But its not working, I am actually using command buttons of RadGrid. I have tried to use this script as I have ajaxified my grid.
I have programmatically binded DataSource to this grid. When I click on the export button on top of grid. Page gets refreshed but there is no export behavior shown by RadGrid.
If you have seen such scenario, please tell me the way out.
Regards.
0
Hi Sheeraz,
Could you please elaborate a little bit more on your scenario? Sending us your code declaration and the related code behind will help us to pinpoint the reason for this behavior.
Greetings,
Kostadin
the Telerik team
Could you please elaborate a little bit more on your scenario? Sending us your code declaration and the related code behind will help us to pinpoint the reason for this behavior.
Greetings,
Kostadin
the Telerik team
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to their blog feed now.
0

Theo
Top achievements
Rank 1
answered on 16 Jan 2013, 06:39 PM
was this ever solved? I am having the same issue. I just put a RadGrid on the page. Configured it included the "ShowExportToExcelButton="true"" and when I run it and click the export button, nothing happens.
Please Help.
Thanks
Here is my code:
Please Help.
Thanks
Here is my code:
<%@ Page Title="" Language="C#" MasterPageFile="~/MasterPage.master" AutoEventWireup="true" CodeFile="SoftCreditsLogFile.aspx.cs" Inherits="SoftCreditsLogFile" %>
<
asp:Content
ID
=
"Content1"
ContentPlaceHolderID
=
"head"
runat
=
"Server"
>
</
asp:Content
>
<
asp:Content
ID
=
"Content2"
ContentPlaceHolderID
=
"ContentPlaceHolder1"
runat
=
"Server"
>
<
h5
>Soft Credit Log</
h5
>
<
div
class
=
"headline"
> </
div
>
<
telerik:RadAjaxLoadingPanel
runat
=
"server"
ID
=
"RadAjaxLoadingPanelSoftCreditsLogFile"
></
telerik:RadAjaxLoadingPanel
>
<
div
class
=
"mainWrapper"
>
<
telerik:RadGrid
ID
=
"RadGrid1"
runat
=
"server"
DataSourceID
=
"SqlDataSource1"
AllowPaging
=
"true"
Skin
=
"FSU_Gold"
AutoGenerateColumns
=
"false"
AllowSorting
=
"True"
AllowFilteringByColumn
=
"false"
GridLines
=
"None"
OnNeedDataSource
=
"RadGrid1_NeedDataSource"
OnItemCommand
=
"RadGrid1_ItemCommand"
EnableEmbeddedSkins
=
"false"
OnBiffExporting
=
"RadGrid1_BiffExporting"
>
<
ExportSettings
IgnorePaging
=
"true"
>
<
Excel
Format
=
"Biff"
></
Excel
>
</
ExportSettings
>
<
MasterTableView
AllowMultiColumnSorting
=
"false"
AllowNaturalSort
=
"false"
IsFilterItemExpanded
=
"false"
CommandItemDisplay
=
"Top"
>
<
CommandItemSettings
ShowExportToExcelButton
=
"true"
ShowRefreshButton
=
"false"
ShowAddNewRecordButton
=
"false"
ExportToExcelImageUrl
=
"images/ExportToExcel.png"
ExportToExcelText
=
""
></
CommandItemSettings
>
<
NoRecordsTemplate
>
No Soft Credits to display.
</
NoRecordsTemplate
>
<
Columns
>
<
telerik:GridBoundColumn
ItemStyle-Width
=
"80px"
HeaderStyle-Width
=
"80px"
DataField
=
"Date_Entered"
HeaderText
=
"Log Date"
SortExpression
=
"Date_Entered"
UniqueName
=
"Date_Entered"
AllowFiltering
=
"false"
>
</
telerik:GridBoundColumn
>
<
telerik:GridBoundColumn
ItemStyle-Width
=
"70px"
HeaderStyle-Width
=
"70px"
DataField
=
"Gift_Date"
HeaderText
=
"Gift Date"
SortExpression
=
"Gift_Date"
UniqueName
=
"Gift_Date"
DataFormatString
=
"{0:MM/dd/yyyy}"
>
</
telerik:GridBoundColumn
>
<
telerik:GridBoundColumn
ItemStyle-Width
=
"140px"
HeaderStyle-Width
=
"140px"
DataField
=
"Soft_Credit_Import_Id"
HeaderText
=
"Soft Credit Import ID"
SortExpression
=
"Soft_Credit_Import_Id"
UniqueName
=
"Soft_Credit_Import_Id"
>
</
telerik:GridBoundColumn
>
<
telerik:GridBoundColumn
ItemStyle-Width
=
"90px"
HeaderStyle-Width
=
"90px"
DataField
=
"Gift_System_Id"
HeaderText
=
"Gift System ID"
SortExpression
=
"Gift_System_Id"
UniqueName
=
"Gift_System_Id"
>
</
telerik:GridBoundColumn
>
<
telerik:GridBoundColumn
ItemStyle-Width
=
"70px"
HeaderStyle-Width
=
"70px"
DataField
=
"Amount"
HeaderText
=
"Amount"
SortExpression
=
"Amount"
UniqueName
=
"Amount"
DataFormatString
=
"{0:C}"
>
</
telerik:GridBoundColumn
>
</
Columns
>
<
SortExpressions
>
<
telerik:GridSortExpression
FieldName
=
"Date_Entered"
SortOrder
=
"Descending"
/>
</
SortExpressions
>
</
MasterTableView
>
<
ClientSettings
EnableRowHoverStyle
=
"true"
>
<
Selecting
AllowRowSelect
=
"false"
></
Selecting
>
<
Scrolling
AllowScroll
=
"true"
UseStaticHeaders
=
"True"
/>
</
ClientSettings
>
<
SortingSettings
SortedBackColor
=
"Azure"
EnableSkinSortStyles
=
"false"
></
SortingSettings
>
<
HeaderStyle
Font-Bold
=
"true"
HorizontalAlign
=
"Left"
></
HeaderStyle
>
</
telerik:RadGrid
>
<
br
/>
</
div
>
<
asp:SqlDataSource
ID
=
"SqlDataSource1"
ConnectionString="<%$ ConnectionStrings:DB %>"
SelectCommand="Select * FROM SoftCreditLog"
runat="server"></
asp:SqlDataSource
>
</
asp:Content
>
using
System;
using
System.Collections.Generic;
using
System.Linq;
using
System.Web;
using
System.Web.UI;
using
System.Web.UI.WebControls;
using
Telerik.Web;
using
Telerik.Web.UI;
public
partial
class
SoftCreditsLogFile : System.Web.UI.Page
{
protected
void
Page_Load(
object
sender, EventArgs e)
{
}
protected
void
RadGrid1_NeedDataSource(
object
source, GridNeedDataSourceEventArgs e)
{
string
gridSortString =
this
.RadGrid1.MasterTableView.SortExpressions.GetSortString();
DataSourceSelectArguments args =
new
DataSourceSelectArguments(gridSortString);
RadGrid1.DataSource =
this
.SqlDataSource1.Select(args);
}
}
0

Shinu
Top achievements
Rank 2
answered on 17 Jan 2013, 05:13 AM
Hi,
After inspecting your code, I can find that you are using both declarative and NeedDataSource events to bind the grid. Try removing any of these and check whether exporting works.
Thanks,
Shinu
After inspecting your code, I can find that you are using both declarative and NeedDataSource events to bind the grid. Try removing any of these and check whether exporting works.
Thanks,
Shinu
0

Sheeraz
Top achievements
Rank 1
answered on 17 Jan 2013, 06:56 AM
Dear Theo
Export feature does not work with ajax. It needs Postback to export. Change your code according to the following.
in ASP Page
Hope this will help you out.
Export feature does not work with ajax. It needs Postback to export. Change your code according to the following.
protected void Page_Load(object sender, EventArgs e)
{
try
{
if (Page.IsPostBack)
{
this.grdReport.DataSource = ViewState["PRF_Report"];
}
}
catch (Exception ex)
{
}
}
protected void grdReport_NeedDataSource(object sender, GridNeedDataSourceEventArgs e)
{
dtReport = new dsSCTimeReport.View_SC_TimeSheet_Actual_Estimated_ComparisonDataTable();
daReport = new dsSCTimeReportTableAdapters.View_SC_TimeSheet_Actual_Estimated_ComparisonTableAdapter();
daReport.Fill(dtReport);
ViewState["PRF_Report"] = dtReport;
grdReport.DataSource = ViewState["PRF_Report"];
}
protected void grdReport_ItemCommand(object sender, Telerik.Web.UI.GridCommandEventArgs e)
{
if (e.CommandName == Telerik.Web.UI.RadGrid.ExportToExcelCommandName)
{
ConfigureExport(grdReport);
grdReport.ExportSettings.FileName = "Planned_Vs_Actual_Report";
}
}
public void ConfigureExport(RadGrid grid)
{
grid.ExportSettings.ExportOnlyData = true;
grid.ExportSettings.IgnorePaging = true;
grid.ExportSettings.OpenInNewWindow = true;
}
in ASP Page
<%@ Register Assembly="Telerik.Web.UI" Namespace="Telerik.Web.UI" TagPrefix="telerik" %>
<
asp:Content
ID
=
"Content1"
ContentPlaceHolderID
=
"HeadContent"
runat
=
"server"
>
<
style
type
=
"text/css"
>
.gridheaders
{
font-size: medium;
font-weight: bold;
}
</
style
>
</
asp:Content
>
<
asp:Content
ID
=
"Content2"
ContentPlaceHolderID
=
"MainContent"
runat
=
"server"
>
<
table
style
=
"width: 100%;"
>
<
tr
>
<
td
class
=
"gridheaders"
>
Planned Vs Estimated Man-Hours
</
td
>
</
tr
>
<
tr
>
<
td
>
<
telerik:RadGrid
ID
=
"grdReport"
runat
=
"server"
AutoGenerateColumns
=
"False"
AllowFilteringByColumn
=
"true"
Width
=
"1050px"
AllowSorting
=
"True"
CellSpacing
=
"0"
GridLines
=
"Both"
EnableViewState
=
"true"
OnNeedDataSource
=
"grdReport_NeedDataSource"
OnItemCommand
=
"grdReport_ItemCommand"
Height
=
"700px"
ShowFooter
=
"true"
Skin
=
"WebBlue"
>
<
MasterTableView
Width
=
"100%"
CommandItemDisplay
=
"Top"
ShowFooter
=
"true"
GridLines
=
"Both"
>
<
CommandItemSettings
ShowAddNewRecordButton
=
"false"
ShowExportToExcelButton
=
"true"
ShowRefreshButton
=
"false"
/>
<
Columns
>
<
telerik:GridBoundColumn
DataField
=
"PRF_Ref"
UniqueName
=
"PRF_Ref"
HeaderText
=
"PRF Reference #"
>
<
ItemStyle
Width
=
"150px"
/>
<
HeaderStyle
Width
=
"150px"
/>
</
telerik:GridBoundColumn
>
<
telerik:GridBoundColumn
DataField
=
"SC_ProposalNo"
UniqueName
=
"SC_ProposalNo"
HeaderText
=
"Proposal #"
>
<
ItemStyle
Width
=
"150px"
/>
<
HeaderStyle
Width
=
"150px"
/>
</
telerik:GridBoundColumn
>
<
telerik:GridBoundColumn
UniqueName
=
"ProjectTitle"
DataField
=
"ProjectTitle"
HeaderText
=
"Project Title"
>
<
ItemStyle
Width
=
"350px"
/>
<
HeaderStyle
Width
=
"350px"
/>
</
telerik:GridBoundColumn
>
<
telerik:GridBoundColumn
DataField
=
"Manhours_Expected"
UniqueName
=
"Manhours_Expected"
HeaderText
=
"Expected Hours"
>
<
ItemStyle
Width
=
"100px"
/>
<
HeaderStyle
Width
=
"100px"
/>
</
telerik:GridBoundColumn
>
<
telerik:GridBoundColumn
DataField
=
"SC_PlannedManhours"
UniqueName
=
"SC_PlannedManhours"
HeaderText
=
"Planned Hours"
>
<
ItemStyle
Width
=
"100px"
/>
<
HeaderStyle
Width
=
"100px"
/>
</
telerik:GridBoundColumn
>
<
telerik:GridBoundColumn
DataField
=
"ActualHours"
UniqueName
=
"ActualHours"
HeaderText
=
"Actual Hours"
>
<
ItemStyle
Width
=
"100px"
/>
<
HeaderStyle
Width
=
"100px"
/>
</
telerik:GridBoundColumn
>
</
Columns
>
<
EditFormSettings
>
</
EditFormSettings
>
</
MasterTableView
>
<
ClientSettings
>
<
Scrolling
AllowScroll
=
"True"
UseStaticHeaders
=
"True"
SaveScrollPosition
=
"True"
>
</
Scrolling
>
<
Selecting
AllowRowSelect
=
"true"
/>
</
ClientSettings
>
<
HeaderContextMenu
CssClass
=
"GridContextMenu GridContextMenu_Vista"
>
</
HeaderContextMenu
>
</
telerik:RadGrid
>
</
td
>
</
tr
>
</
table
>
</
asp:Content
>
Hope this will help you out.
0

Charan
Top achievements
Rank 1
answered on 17 Jan 2013, 02:15 PM
Hi,
I have a problem while exporting to excel.
i have radgrid inside update panel and i have registered button for full post back.
i am able to export the data to excel but the problem is whatever data is displayed in literals are not getting displayed in the excel sheet.
any solution for this problem?
Thanks,
Charan
I have a problem while exporting to excel.
i have radgrid inside update panel and i have registered button for full post back.
i am able to export the data to excel but the problem is whatever data is displayed in literals are not getting displayed in the excel sheet.
any solution for this problem?
Thanks,
Charan
0

Shinu
Top achievements
Rank 2
answered on 18 Jan 2013, 05:46 AM
Hi,
Try setting the following.
aspx:
Thanks,
Shinu
Try setting the following.
aspx:
<
ExportSettings
ExportOnlyData
=
"false"
></
ExportSettings
>
Thanks,
Shinu
0

Charan
Top achievements
Rank 1
answered on 18 Jan 2013, 06:24 AM
Hi Shinu,
There are certain links, which i don't want to be displayed as links instead to be displayed just as text.
so i cant set
Thanks
Charan
There are certain links, which i don't want to be displayed as links instead to be displayed just as text.
so i cant set
ExportOnlyData
as false.Thanks
Charan
0

Theo
Top achievements
Rank 1
answered on 18 Jan 2013, 02:49 PM
Shinu,
I removed the declarative and it still did not work. I have to use the NeedDataSource event. Do you have any other ideas?
I removed the declarative and it still did not work. I have to use the NeedDataSource event. Do you have any other ideas?
0

Theo
Top achievements
Rank 1
answered on 18 Jan 2013, 03:06 PM
Sheeraz,
Thank you for your code sample. I integrated the relevant parts into my code and it still does not work. It looks like you have two custom classes in your NeedDataSource event. There is something wierd with this approach because the command item on my radgrid disappears when I click the "Export to Excel" button. What are you doing in your custom classes? Any assistance is helpful. Thanks This is how I updated NeedDataSource:
Thank you for your code sample. I integrated the relevant parts into my code and it still does not work. It looks like you have two custom classes in your NeedDataSource event. There is something wierd with this approach because the command item on my radgrid disappears when I click the "Export to Excel" button. What are you doing in your custom classes? Any assistance is helpful. Thanks This is how I updated NeedDataSource:
protected
void
RadGrid1_NeedDataSource(
object
source, GridNeedDataSourceEventArgs e)
{
string
gridSortString =
this
.RadGrid1.MasterTableView.SortExpressions.GetSortString();
//string text = "Grid sort expression: " + gridSortString;
//RadAjaxManager1.ResponseScripts.Add(string.Format("document.getElementById('{0}').innerHTML = '" + text + "';", this.SortLabel.ClientID));
DataSourceSelectArguments args =
new
DataSourceSelectArguments(gridSortString);
//RadGrid1.DataSource = this.SqlDataSource1.Select(args);
//////////////////////////////////////////////////////////////////////////////////////////////////
//dtReport = new dsSCTimeReport.View_SC_TimeSheet_Actual_Estimated_ComparisonDataTable();
//daReport = new dsSCTimeReportTableAdapters.View_SC_TimeSheet_Actual_Estimated_ComparisonTableAdapter();
//daReport.Fill(dtReport);
DataTable dt = ((DataView)
this
.SqlDataSource1.Select(args)).Table;
ViewState[
"SoftCreditsLogFile"
] = dt;
RadGrid1.DataSource = ViewState[
"SoftCreditsLogFile"
];
}
0

Shinu
Top achievements
Rank 2
answered on 21 Jan 2013, 05:32 AM
Hi,
Try the following code to achieve your scenario.
C#:
Thanks,
Shinu
Try the following code to achieve your scenario.
C#:
protected
void
RadGrid1_ExportCellFormatting(
object
sender, ExportCellFormattingEventArgs e)
{
GridDataItem item = e.Cell.Parent
as
GridDataItem;
if
(e.FormattedColumn.UniqueName ==
"ColumnUniqueName"
)
{
TableCell cell = item[
"ColumnUniqueName"
];
LinkButton link = (LinkButton)item.FindControl(
"LinkButton1"
);
cell.Text = link.Text;
}
}
Thanks,
Shinu
0

Charan
Top achievements
Rank 1
answered on 22 Jan 2013, 12:22 PM
Thanks for the solution Shinu