
I have an RadGridView within an UpdatePanel and I want to export it to Excel. Than I discover a problem. I've already knew that Button which triggers the actual export should be registered as an postback control. I did it (according to the way found on telerik website). But it does not work. My GridView looks like this
<telerik:RadGrid ID="gvSearchTelerik" runat="server" |
OnItemCreated="gvSearchTelerik_ItemCreated" |
EnableAjaxSkinRendering="false" |
AllowSorting="True" |
AllowPaging="True" |
PageSize="15" |
GridLines="None" |
Width="100%" |
AllowFilteringByColumn="True" |
DataSourceID="sqlSearchDevice" |
HeaderStyle-Wrap="false" |
HeaderStyle-Width="150px" |
ShowGroupPanel="True" |
ShowStatusBar="true"> |
<MasterTableView CommandItemDisplay="Top"> |
<CommandItemTemplate> |
<asp:ImageButton ID="bXls" runat="server" |
OnInit="bXls_Init" |
OnPreRender="bXls_PreRender" |
OnClick="bXls_Click" |
style="margin:3px 2px 1px 2px" |
SkinID="ExportToExcel"/> |
</CommandItemTemplate> |
<Columns> |
<telerik:GridBoundColumn DataField="Id" DataType="System.Int32" |
HeaderText="MojeIdecko"> |
</telerik:GridBoundColumn> |
</Columns> |
</MasterTableView> |
<PagerStyle Mode="NextPrevAndNumeric"></PagerStyle> |
<ExportSettings IgnorePaging="true" OpenInNewWindow="true" ExportOnlyData="true" > |
<Excel FileExtension="xls" Format="ExcelML" /> |
</ExportSettings> |
<ClientSettings AllowDragToGroup="True" |
AllowColumnsReorder="true" |
ReorderColumnsOnClient="true"> |
<Scrolling AllowScroll="True" |
UseStaticHeaders="True" |
SaveScrollPosition="true" |
FrozenColumnsCount="1" /> |
</ClientSettings> |
</telerik:RadGrid> |
it is placed in the content page of a master page. Update panel is placed over the whole content in the master page. The code behind of the export function is
protected void bXls_Click(object sender, ImageClickEventArgs e) |
{ |
gvSearchTelerik.ExportSettings.ExportOnlyData = true; |
gvSearchTelerik.ExportSettings.IgnorePaging = true; |
gvSearchTelerik.ExportSettings.OpenInNewWindow = true; |
gvSearchTelerik.MasterTableView.ExportToExcel(); |
} |
i registered the button as postback control in the ItemCreated event of the gridview
protected void gvSearchTelerik_ItemCreated(object sender, Telerik.Web.UI.GridItemEventArgs e) |
{ |
if (e.Item is GridCommandItem) |
{ |
ImageButton ibExportToExcel = (e.Item as GridCommandItem).FindControl("bXls") as ImageButton; |
this.RegisterPostbackControl(this, ibExportToExcel); //this function just registers input control // via ScriptManager placed on the MasterPage |
} |
} |
however, each time i click the export button an asynchronous postback is made, not just fullpostback and GridView is not exported.
I tried other solution written on the telerik website, but non of them seem to work. What I've discovered was fact that export is made only for the first time. In other words, export is working, but when i made some postback on the page, export button does not cause full postback anymore.
please help.
thanks
17 Answers, 1 is accepted
Modify your code this way and let me know whether this helps.
protected
void
gvSearchTelerik_ItemCreated(
object
sender, GridItemEventArgs e)
{
if
(e.Item
is
GridCommandItem)
{
ImageButton ibExportToExcel = (e.Item
as
GridCommandItem).FindControl(
"bXls"
)
as
ImageButton;
ScriptManager.GetCurrent(
this
.Page).RegisterPostBackControl(ibExportToExcel);
}
}
Exclude controls from ajaxifying
Best regards,
Daniel
the Telerik team
Instantly find answers to your questions on the new Telerik Support Portal.
Watch a video on how to optimize your support resource searches and check out more tips on the blogs.

this.RegisterPostbackControl(this, ibExportToExcel); |
already looks like this
public void RegisterPostbackControl(Page page, Control postbackControl) |
{ |
ScriptManager sm = ScriptManager.GetCurrent(page); |
sm.RegisterPostBackControl(postbackControl); |
} |
what is actually the same. This method is placed inside the BasePage class which is inheriting from the Web.UI.Page class and each content page is inheriting from this BasePage class. In other parts of the web application it is working but not here. I tried to register the export button as postback control in various other events (DataBound event of the GridView, OnInit/OnPrerender of the export button itself) but with the same result. When the page is built for the first time and grid is empty, export button works. But when I type some search criteria and press search button, async postback is fired, gridview is databound with new data and export button does not work as full postback trigger anymore. The sql datasource of the gridview has some select parameters bound to the asp elements (TextBox, ListBox etc.). This should not be problem.
I tried also placing the export button inside the new update panel and registering it as postback trigger with it.
<MasterTableView CommandItemDisplay="Top"> |
<CommandItemTemplate> |
<asp:UpdatePanel ID="up" runat="server"> |
<Triggers> |
<asp:PostBackTrigger ControlID="bXls" /> |
</Triggers> |
<ContentTemplate> |
<asp:ImageButton ID="bXls" runat="server" |
OnInit="bXls_Init" |
OnPreRender="bXls_PreRender" |
OnClick="bXls_Click" |
style="margin:3px 2px 1px 2px" |
SkinID="ExportToExcel"/> |
</ContentTemplate> |
</asp:UpdatePanel> |
</CommandItemTemplate> |
</MasterTableView> |
this way works fine for asp:GridView but with RadGridView I get the following error:
Cannot unregister UpdatePanel with ID 'up' since it was not registered with the ScriptManager. This might occur if the UpdatePanel was removed from the control tree and later added again, which is not supported. Parameter name: updatePanel
I am ran out of options.
This approach is working fine on my end. Please download the attached sample project and let me know whether it behaves as expected. Note that I don't have nested UpdatePanels.
Regards,
Daniel
the Telerik team
Instantly find answers to your questions on the new Telerik Support Portal.
Watch a video on how to optimize your support resource searches and check out more tips on the blogs.

your project works fine, but it is not a solution.
I modified your project as follows
<telerik:RadGrid ID="RadGrid1" runat="Server" OnItemCreated="RadGrid1_ItemCreated" |
EnableAjaxSkinRendering="false" |
AllowSorting="True" |
AllowPaging="True" |
PageSize="15" |
GridLines="None" |
Width="100%" |
AllowFilteringByColumn="True" |
HeaderStyle-Wrap="false" |
HeaderStyle-Width="150px" |
ShowGroupPanel="True" |
ShowStatusBar="true"> |
<MasterTableView CommandItemDisplay="Top"> |
<CommandItemTemplate> |
<asp:Button ID="Button1" runat="server" CommandName="ExportToExcel" Text="Export" /> |
</CommandItemTemplate> |
</MasterTableView> |
<PagerStyle Mode="NextPrevAndNumeric"></PagerStyle> |
<ExportSettings IgnorePaging="true" OpenInNewWindow="true" ExportOnlyData="true" > |
<Excel FileExtension="xls" Format="ExcelML" /> |
</ExportSettings> |
<ClientSettings AllowDragToGroup="True" |
AllowColumnsReorder="true" |
ReorderColumnsOnClient="true"> |
<Scrolling AllowScroll="True" |
UseStaticHeaders="True" |
SaveScrollPosition="true" |
FrozenColumnsCount="1" /> |
</ClientSettings> |
</telerik:RadGrid> |
<asp:Button id="bDoPostback" runat="server" Text="Do postback" OnClick="bDoPostback_Click"/> |
code behind:
protected void Page_Load(object sender, EventArgs e) |
{ |
RadGrid1.DataSource = new int[] { 1, 2, 3, }; |
} |
protected void RadGrid1_ItemCreated(object sender, Telerik.Web.UI.GridItemEventArgs e) |
{ |
if (e.Item is GridCommandItem) |
ScriptManager.GetCurrent(Page).RegisterPostBackControl(e.Item.FindControl("Button1")); |
} |
protected void bDoPostback_Click(object sender, EventArgs e) |
{ |
RadGrid1.DataSource = new int[] { 1, 2, 3, 4, 5, 6}; |
RadGrid1.DataBind(); |
} |
master page:
<%@ Master Language="C#" AutoEventWireup="true" CodeFile="MasterPage.master.cs" Inherits="MasterPage" %> |
<%@ Register Assembly="Telerik.Web.UI" Namespace="Telerik.Web.UI" TagPrefix="telerik" %> |
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"> |
<html xmlns="http://www.w3.org/1999/xhtml"> |
<head runat="server"> |
<meta http-equiv="x-ua-compatible" content="IE=8"/> |
<asp:ContentPlaceHolder ID="head" runat="server"> |
</asp:ContentPlaceHolder> |
</head> |
<body> |
<form id="form1" runat="server"> |
<asp:ScriptManager ID="ScriptManager1" runat="server" /> |
<div> |
<asp:UpdatePanel ID="UpdatePanel1" runat="server"> |
<ContentTemplate> |
<asp:ContentPlaceHolder ID="ContentPlaceHolder1" runat="server"> |
</asp:ContentPlaceHolder> |
</ContentTemplate> |
</asp:UpdatePanel> |
</div> |
</form> |
</body> |
</html> |
now, when page is built, I click on the bDoPostback button. Async postback is triggered. Grid is databound with new data. Everything seems to be fine. But when I click the export button an async postback is triggered (not full postback), grid has changed it's view according to the export settings and nothing has been exported. I click the bDoPostback again. Grid is databound again and it's view is back to normal. Then I click export button. GridView has been exported now with no problems. I do not get it. But it seems to me like the setting changes I made to the GridView influence the behaviour somehow. Could you please check it out? thanks
There are two major problems in this case:
- UseStaticHeaders should be set to false when exporting
- UseAllDataFields should be set to true when binding to array
Regards,
Daniel
the Telerik team
Instantly find answers to your questions on the new Telerik Support Portal.
Watch a video on how to optimize your support resource searches and check out more tips on the blogs.

export works now. Thank you very much.
But it would be nice if the export could work with the previous scrolling settings.
regards
martin

How come a feature that should be purely cosmetic on the UI has such s significant effect on a functionality that has nothing to do with what the UI on the page looks like?
So did I understand correctly that we can either have static headers on our grid or export to excel functionality but not both?
Or is there some trick to set static headers to false at some particular stage of the page life cycle and set it back to true after exporting is done?
Do you have a real solution to this problem?
How come a feature that should be purely cosmetic on the UI has such s significant effect on a functionality that has nothing to do with what the UI on the page looks like?
The rendering of the control with static headers and scrolling is different.
So did I understand correctly that we can either have static headers on our grid or export to excel functionality but not both?
You can have both of them. You don't even need to re-enable this functionality when exporting since the response will be redirected and this change won't affect your page at all.
To put the long story short, you have to set the StaticHeaders to false and then export the control as usual. You don't need to perform any additional steps.
Or is there some trick to set static headers to false at some particular stage of the page life cycle and set it back to true after exporting is done?
This is not needed. See above.
Regards,
Daniel
the Telerik team
Browse the vast support resources we have to jump start your development with RadControls for ASP.NET AJAX. See how to integrate our AJAX controls seamlessly in SharePoint 2007/2010 visiting our common SharePoint portal.

>The rendering of the control with static headers and scrolling is different.
Yes it is. But this is in the web client UI, in the browser. Why should this affect the excel document generation?
>So did I understand correctly that we can either have static headers on our grid or export to excel functionality but not both?
>You can have both of them. You don't even need to re-enable this functionality when exporting since the response will be redirected and this change won't affect your page at all.
>To put the long story short, you have to set the StaticHeaders to false and then export the control as usual. You don't need to perform any additional steps.
This did not work for us. Maybe because we do things a little bit differently in this application. On every request the grid gets a fresh set of data that is bound at Page_PreRender. There are no if(!IsPostback) lines anywhere in our code behinds. Could this affect the excel generation?
What we tried was:
at the gird's ItemCreated handler we register the excel button as a postback button like so
ScriptManager sm = ScriptManager.GetCurrent(this.Page);
sm.RegisterPostBackControl(e.Item.FindControl("exportExcelButton"));
Then we tried the following things
1) In the excel button's click handler:
grid.ClientSettings.Scrolling.UseStaticHeaders = false;
grid.MasterTableView.ExportToExcel();
This caused the following behaviour:
When the button is clicked once, excel is not generated but the static headers are set to false and this reflected in the UI (headers no longer static)
When the button was clicked the second time the excel was generated and given in the response. But still the headers are not static anymore.
2)In the excel button's click handled we set a boolean instance variable export to true
After this at Page_PreRender after new set of data is bound we set the static headers to false and called export to excel
This cause the following behaviour:
When the button is clicked the partial ajax postback is made but the response never returns
I also tried all combinations I could think of of these scenarios: not binding new data if export is clicked, calling export to excel in different places, setting static headers to false in different places. Nothing worked.

1) We are using ASP.NET UpdatePanels not Telerik panels
- UpdatePanels have UpdateMode=Conditional and ChildrenAsTriggers=True
2) If you don't have some ideas how we could fix this soonish, could you reply to this thread and tell, so we could maybe drop the exceling tasks from this sprint and concentrate on something else. We will try to get this working for a couple of days, but then we might have to drop the features from this sprint or if it looks like it will take too long to get it working.
Yes it is. But this is in the web client UI, in the browser. Why should this affect the excel document generation?
The exported content is based on the rendering of the control (except when using ExcelML).
This did not work for us. Maybe because we do things a little bit differently in this application. On every request the grid gets a fresh set of data that is bound at Page_PreRender. There are no if(!IsPostback) lines anywhere in our code behinds. Could this affect the excel generation?
I don't believe this is a databinding issue. I created a sample project to demonstrate how to implement my suggestions in a scenario similar to yours. Test it at your side and let me know whether it behaves as expected.
As to the AJAX-related problem - I recommend that you use client-side code to cancel the ajax request.
Sys.WebForms.PageRequestManager.getInstance().add_initializeRequest(initializeRequestHandler);
function
initializeRequestHandler(sender, args)
{
if
(args.get_postBackElement().id.indexOf(
"CONTROL_ID"
) != -1)
{
args.set_cancel(
true
);
sender._form[
"__EVENTTARGET"
].value = args.get_postBackElement().id.replace(/\_/g,
"$"
);
sender._form[
"__EVENTARGUMENT"
].value =
""
;
sender._form.submit();
return
;
}
}
You can also test this code in the sample project. Note that you have to replace the CONTROL_ID string with the ID of the control that triggers the export.
Regards,
Daniel
the Telerik team
Browse the vast support resources we have to jump start your development with RadControls for ASP.NET AJAX. See how to integrate our AJAX controls seamlessly in SharePoint 2007/2010 visiting our common SharePoint portal.

However we ran into another problem. When we use the ExcelML format we don't get any data in our excel document. With the html format we get data in the document.
I have not been able to reproduce this problem on the example you provided,
I will continue to look into this and reply to this thread if I find the source of the problem and/or solution.
EDIT: I was able to reproduce the problem by binding to a List of Foo objects instead of Datatable.
public class Foo
public
class
Foo
{
private
int
id;
public
int
ID
{
get
{
return
id; }
set
{ id = value; }
}
private
string
baz;
public
string
Baz
{
get
{
return
baz; }
set
{ baz = value; }
}
private
string
bar;
public
string
Bar
{
get
{
return
bar; }
set
{ bar = value; }
}
}
I then bound a List of these Foo objects to the grid in Page_PreRender like so:
List<Foo> foos =
new
List<Foo>(20);
for
(
int
i = 0; i < 20; i++)
foos.Add(
new
Foo { ID=1, Baz=
"Foo_"
+i, Bar=
"Bar_"
+i });
RadGrid1.VirtualItemCount = 2000;
RadGrid1.CurrentPageIndex = 0;
RadGrid1.PageSize = 100;
RadGrid1.DataSource = foos;
RadGrid1.DataBind();
The markup looks like this now:
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="WebForm1.aspx.cs" Inherits="ExcelExample.WebForm1" %>
<%@ Register TagPrefix="telerik" Assembly="Telerik.Web.UI" Namespace="Telerik.Web.UI" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<
html
xmlns
=
"http://www.w3.org/1999/xhtml"
>
<
head
runat
=
"server"
>
<
title
></
title
>
</
head
>
<
body
>
<
form
id
=
"form1"
runat
=
"server"
>
<
asp:ScriptManager
ID
=
"ScriptManager1"
runat
=
"server"
/>
<
script
type
=
"text/javascript"
>
Sys.WebForms.PageRequestManager.getInstance().add_initializeRequest(initializeRequestHandler);
function initializeRequestHandler(sender, args) {
if (args.get_postBackElement().id.indexOf("exportExcelButton") != -1) {
args.set_cancel(true);
sender._form["__EVENTTARGET"].value = args.get_postBackElement().id.replace(/\_/g, "$");
sender._form["__EVENTARGUMENT"].value = "";
sender._form.submit();
return;
}
}
</
script
>
<
div
>
<
asp:UpdatePanel
ID
=
"UpdatePanel1"
runat
=
"server"
UpdateMode
=
"Conditional"
ChildrenAsTriggers
=
"true"
>
<
ContentTemplate
>
<
telerik:RadGrid
ID
=
"RadGrid1"
runat
=
"server"
Width
=
"600px"
EnableViewState
=
"true"
PageSize
=
"100"
AutoGenerateColumns
=
"false"
onitemdatabound
=
"RadGrid1_ItemDataBound"
AllowMultiRowSelection
=
"true"
AllowPaging
=
"true"
AllowSorting
=
"true"
AllowCustomPaging
=
"true"
AllowNaturalSort
=
"False"
onitemcreated
=
"RadGrid1_ItemCreated"
ShowStatusBar
=
"true"
onexcelexportcellformatting
=
"RadGrid1_ExcelExportCellFormatting"
>
<
ExportSettings
FileName
=
"alarms"
OpenInNewWindow
=
"True"
ExportOnlyData
=
"true"
IgnorePaging
=
"true"
>
<
Excel
Format
=
"ExcelML"
/>
<
Csv
EncloseDataWithQuotes
=
"true"
/>
<
Excel
Format
=
"ExcelML"
/><
Csv
EncloseDataWithQuotes
=
"true"
/></
ExportSettings
>
<
MasterTableView
CommandItemDisplay
=
"Top"
AllowCustomSorting
=
"true"
>
<
CommandItemTemplate
>
<
asp:Button
ID
=
"exportExcelButton"
runat
=
"server"
Text
=
"Export"
OnClick
=
"exportExcelButton_Click"
/>
<
asp:Button
ID
=
"PostbackButton"
runat
=
"server"
Text
=
"Postback"
/>
</
CommandItemTemplate
>
<
Columns
>
<
telerik:GridTemplateColumn
UniqueName
=
"CheckBoxSelection"
HeaderStyle-Width
=
"25"
ItemStyle-Width
=
"25"
ItemStyle-HorizontalAlign
=
"Center"
Resizable
=
"false"
>
<
HeaderTemplate
>
<
asp:CheckBox
Width
=
"25"
ID
=
"headerCheckBox"
OnCheckedChanged
=
"headerCheckBox_CheckedChanged"
AutoPostBack
=
"True"
runat
=
"server"
></
asp:CheckBox
>
</
HeaderTemplate
>
<
ItemTemplate
>
<
asp:CheckBox
ID
=
"CheckBox"
OnCheckedChanged
=
"CheckBox_Clicked"
AutoPostBack
=
"True"
runat
=
"server"
></
asp:CheckBox
>
</
ItemTemplate
>
<
HeaderStyle
Width
=
"25px"
></
HeaderStyle
>
<
ItemStyle
HorizontalAlign
=
"Center"
Width
=
"25px"
></
ItemStyle
>
</
telerik:GridTemplateColumn
>
<
telerik:GridBoundColumn
UniqueName
=
"ID"
HeaderText
=
"ID"
DataField
=
"ID"
>
<
HeaderStyle
Width
=
"20%"
/>
</
telerik:GridBoundColumn
>
<
telerik:GridButtonColumn
UniqueName
=
"C2"
HeaderText
=
"C2"
ButtonType
=
"ImageButton"
>
<
HeaderStyle
Width
=
"20%"
/>
</
telerik:GridButtonColumn
>
<
telerik:GridBoundColumn
UniqueName
=
"Baz"
HeaderText
=
"Baz"
DataField
=
"Baz"
>
<
HeaderStyle
Width
=
"20%"
/>
</
telerik:GridBoundColumn
>
<
telerik:GridBoundColumn
UniqueName
=
"Bar"
HeaderText
=
"Bar"
DataField
=
"Bar"
>
<
HeaderStyle
Width
=
"20%"
/>
</
telerik:GridBoundColumn
>
<
telerik:GridButtonColumn
UniqueName
=
"C4"
HeaderText
=
"C4"
ButtonType
=
"LinkButton"
>
<
HeaderStyle
Width
=
"20%"
/>
</
telerik:GridButtonColumn
>
</
Columns
>
<
PagerStyle
Wrap
=
"true"
AlwaysVisible
=
"True"
Mode
=
"NextPrevAndNumeric"
/>
</
MasterTableView
>
<
ClientSettings
EnablePostBackOnRowClick
=
"true"
EnableRowHoverStyle
=
"true"
>
<
Scrolling
AllowScroll
=
"true"
UseStaticHeaders
=
"true"
/>
<
Scrolling
AllowScroll
=
"true"
UseStaticHeaders
=
"true"
/></
ClientSettings
>
<
FilterMenu
EnableImageSprites
=
"False"
>
</
FilterMenu
>
<
HeaderContextMenu
CssClass
=
"GridContextMenu GridContextMenu_Default"
>
</
HeaderContextMenu
>
</
telerik:RadGrid
>
</
ContentTemplate
>
</
asp:UpdatePanel
>
</
div
>
</
form
>
</
body
>
</
html
>
The whole codebehind here, since I cant attach the solution as a .rar. There is some copy-pasted code from the actual app. I added the activate.png there to test whether it was causing any problems.
using
System;
using
System.Collections.Generic;
using
System.Linq;
using
System.Web;
using
System.Web.UI;
using
System.Web.UI.WebControls;
using
System.Data;
using
Telerik.Web.UI;
namespace
ExcelExample
{
public
partial
class
WebForm1 : System.Web.UI.Page
{
protected
void
Page_Init(
object
sender, EventArgs e)
{
Page.LoadComplete +=
new
EventHandler(Page_LoadComplete);
}
void
Page_LoadComplete(
object
sender, EventArgs e)
{
foreach
(GridDataItem item
in
RadGrid1.MasterTableView.Items)
{
if
(item.Selected)
{
selectedItems.Add(item[
"C1"
].Text);
}
}
}
protected
void
Page_PreRender(
object
sender, EventArgs e)
{
List<Foo> foos =
new
List<Foo>(20);
for
(
int
i = 0; i < 20; i++)
foos.Add(
new
Foo { ID=1, Baz=
"Foo_"
+i, Bar=
"Bar_"
+i });
RadGrid1.VirtualItemCount = 2000;
RadGrid1.CurrentPageIndex = 0;
RadGrid1.PageSize = 100;
RadGrid1.DataSource = foos;
RadGrid1.DataBind();
bool
allSelected =
true
;
foreach
(GridDataItem item
in
RadGrid1.MasterTableView.Items)
{
if
(selectedItems.Contains(item[
"Baz"
].Text))
{
item.Selected =
true
;
}
else
{
allSelected =
false
;
}
}
if
(allSelected)
{
}
}
private
HashSet<
string
> selectedItems =
new
HashSet<
string
>();
private
bool
export =
false
;
protected
void
exportExcelButton_Click(
object
sender, EventArgs e)
{
RadGrid1.ClientSettings.Scrolling.AllowScroll =
false
;
RadGrid1.ClientSettings.Scrolling.UseStaticHeaders =
false
;
RadGrid1.MasterTableView.ExportToExcel();
export =
true
;
}
protected
void
RadGrid1_ItemDataBound(
object
sender, Telerik.Web.UI.GridItemEventArgs e)
{
if
(e.Item
is
GridDataItem)
{
GridDataItem dataItem = e.Item
as
GridDataItem;
ImageButton ibtn = (ImageButton)dataItem[
"C2"
].Controls[0];
ibtn.CommandName =
"Foo"
;
ibtn.ImageUrl =
"activate.png"
;
LinkButton lnkbtn = (LinkButton)dataItem[
"C4"
].Controls[0];
lnkbtn.Text =
"Linky Linky"
;
//Javascript function call. CommandName is the functionand CommandArgument the page to display when clicked.
string
jsFunctionCall = lnkbtn.CommandName +
"('"
+ lnkbtn.CommandArgument +
"?id="
+ 2 +
"');"
;
//Add the function.
lnkbtn.Attributes.Add(
"onClick"
, jsFunctionCall);
}
else
if
(e.Item
is
GridPagerItem)
{
//Paging drop down values must be set here.
GridPagerItem pager = (GridPagerItem)e.Item;
RadComboBox PageSizeComboBox = (RadComboBox)pager.FindControl(
"PageSizeComboBox"
);
PageSizeComboBox.Items.Clear();
PageSizeComboBox.Items.Add(
new
RadComboBoxItem(
"50"
));
PageSizeComboBox.FindItemByText(
"50"
).Attributes.Add(
"ownerTableViewId"
, RadGrid1.MasterTableView.ClientID);
PageSizeComboBox.Items.Add(
new
RadComboBoxItem(
"100"
));
PageSizeComboBox.FindItemByText(
"100"
).Attributes.Add(
"ownerTableViewId"
, RadGrid1.MasterTableView.ClientID);
PageSizeComboBox.Items.Add(
new
RadComboBoxItem(
"250"
));
PageSizeComboBox.FindItemByText(
"250"
).Attributes.Add(
"ownerTableViewId"
, RadGrid1.MasterTableView.ClientID);
//PageSizeComboBox.FindItemByText(e.Item.OwnerTableView.PageSize.ToString()).Selected = true;
}
}
protected
void
CheckBox_Clicked(
object
sender, EventArgs e)
{
((sender
as
CheckBox).NamingContainer
as
GridItem).Selected = (sender
as
CheckBox).Checked;
}
protected
void
headerCheckBox_CheckedChanged(
object
sender, EventArgs e)
{
CheckBox headerCheckBox = (sender
as
CheckBox);
foreach
(GridDataItem dataItem
in
RadGrid1.MasterTableView.Items)
{
(dataItem.FindControl(
"CheckBox"
)
as
CheckBox).Checked = headerCheckBox.Checked;
dataItem.Selected = headerCheckBox.Checked;
}
}
private
void
RadGrid1_ItemPreRender(
object
sender, EventArgs e)
{
if
(!export)
{
((sender
as
GridDataItem)[
"CheckBoxSelection"
].FindControl(
"CheckBox"
)
as
CheckBox).Checked = (sender
as
GridDataItem).Selected;
GridHeaderItem headerItem = RadGrid1.MasterTableView.GetItems(GridItemType.Header)[0]
as
GridHeaderItem;
//Set the "select all" checkbox checked if all facilities are selected.
(headerItem.FindControl(
"headerCheckBox"
)
as
CheckBox).Checked = RadGrid1.SelectedItems.Count == RadGrid1.MasterTableView.Items.Count;
}
}
protected
void
RadGrid1_ItemCreated(
object
sender, GridItemEventArgs e)
{
if
(e.Item
is
GridDataItem)
{
e.Item.PreRender +=
new
EventHandler(RadGrid1_ItemPreRender);
}
}
protected
void
RadGrid1_ExcelExportCellFormatting(
object
sender, ExcelExportCellFormattingEventArgs e)
{
e.Cell.HorizontalAlign = HorizontalAlign.Left;
}
}
}

When exporting to ExcelML format, RadGrid takes the data directly from your datasource thus ignoring any changes made in runtime.
For your convenience I attached a simple demo that shows how to export template columns manually.
The demonstrated approach uses ExcelMLExportRowCreated but you could also use the ExcelMLExportWorkBookCreated event if suitable for your scenario.
Best regards,
Daniel
the Telerik team
Browse the vast support resources we have to jump start your development with RadControls for ASP.NET AJAX. See how to integrate our AJAX controls seamlessly in SharePoint 2007/2010 visiting our common SharePoint portal.


When we use your javascript code, our StatusBar stays in the "loading state" (the loading icon won't disappear) even though we get the excel file. We tried to simply rebind the grids (see the code below) but we get nulls and the script crashes.
Sys.WebForms.PageRequestManager.getInstance().add_initializeRequest(initializeRequestHandler);
function
initializeRequestHandler(sender, args) {
if
(args.get_postBackElement().id.indexOf(
"exportExcelButton"
) != -1) {
args.set_cancel(
true
);
Sys.WebForms.PageRequestManager.getInstance().abortPostBack();
sender._form[
"__EVENTTARGET"
].value = args.get_postBackElement().id.replace(/\_/g,
"$"
);
sender._form[
"__EVENTARGUMENT"
].value =
""
;
sender._form.submit();
sender._form[
"__EVENTTARGET"
].value =
""
;
sender._form[
"__EVENTARGUMENT"
].value =
""
;
$find(
"<%= FacilityMeterHierarchicalView1.ClientID %>"
).get_masterTableView().rebind();
$find(
"<%= setAlarmsListView.ClientID %>"
).get_masterTableView().rebind();
return
;
}
}
Is there another way of setting the status bar to the initiate state?
This code works best with ASP.NET UpdatePanel. It might work with RadAjaxPanel and RadAjaxManager also, but in this case we recommend that you use the built-in events/methods as explained in this topic:
Export from ajaxified grid
Note that it is important not to ajaxify your controls more than once - e.g. to wrap the control in RadAjaxPanel and then ajaxify it with RadAjaxManager.
Ajaxifying controls wrapped in RadAjaxPanel and added to RadAjaxManager settings
Best regards,
Daniel
the Telerik team
Browse the vast support resources we have to jump start your development with RadControls for ASP.NET AJAX. See how to integrate our AJAX controls seamlessly in SharePoint 2007/2010 visiting our common SharePoint portal.