3 Answers, 1 is accepted
0

Shinu
Top achievements
Rank 2
answered on 07 May 2014, 12:36 PM
Hi Damian,
Please have a look into the sample code snippet which works fine at my end.
C#:
Thanks,
Shinu.
Please have a look into the sample code snippet which works fine at my end.
C#:
RadTabStrip tabStrip =
new
RadTabStrip();
RadMultiPage multipage =
new
RadMultiPage();
RadPageView pageView1 =
new
RadPageView();
RadGrid RadGrid1 =
new
RadGrid();
RadButton RadButton1 =
new
RadButton();
protected
void
Page_Load(
object
sender, EventArgs e)
{
//creating tabstrip multipage and button
multipage.ID =
"MultiPage1"
;
pageView1.ID =
"PageView1"
;
tabStrip.ID =
"Tabtrip1"
;
tabStrip.TabClick +=
new
RadTabStripEventHandler(tabStrip_TabClick);
tabStrip.MultiPageID = multipage.ID;
RadTab tab1 =
new
RadTab();
tab1.Text =
"Grid"
;
tab1.PageViewID = pageView1.ID;
tabStrip.Tabs.Add(tab1);
form1.Controls.Add(tabStrip);
multipage.PageViews.Add(pageView1);
multipage.PageViewCreated +=
new
RadMultiPageEventHandler(multipage_PageViewCreated);
RadButton1.Text =
"Export"
;
RadButton1.Click +=
new
EventHandler(RadButton1_Click);
form1.Controls.Add(RadButton1);
form1.Controls.Add(multipage);
}
void
multipage_PageViewCreated(
object
sender, RadMultiPageEventArgs e)
{
//adding grid to the pageview
RadGrid1.DataSourceID =
"SqlDataSource1"
;
RadGrid1.MasterTableView.DataKeyNames =
new
string
[] {
"CustomerID"
};
RadGrid1.Skin =
"Default"
;
RadGrid1.Width = Unit.Percentage(100);
RadGrid1.PageSize = 15;
RadGrid1.AllowPaging =
true
;
RadGrid1.AutoGenerateColumns =
false
;
GridBoundColumn boundColumn;
boundColumn =
new
GridBoundColumn();
boundColumn.DataField =
"CustomerID"
;
boundColumn.HeaderText =
"CustomerID"
;
RadGrid1.MasterTableView.Columns.Add(boundColumn);
boundColumn =
new
GridBoundColumn();
boundColumn.DataField =
"ContactName"
;
boundColumn.HeaderText =
"Contact Name"
;
RadGrid1.MasterTableView.Columns.Add(boundColumn);
pageView1.Controls.Add(RadGrid1);
}
void
tabStrip_TabClick(
object
sender, RadTabStripEventArgs e)
{
e.Tab.PageView.Controls.Add(RadGrid1);
e.Tab.Selected =
true
;
e.Tab.PageView.Selected =
true
;
}
void
RadButton1_Click(
object
sender, EventArgs e)
{
RadGrid1.MasterTableView.ExportToExcel();
}
Thanks,
Shinu.
0

Damian
Top achievements
Rank 1
answered on 12 May 2014, 01:32 PM
Thanks Shinu. This doesn't work with the grid being added via AJAX. I would like to export the grid created in the below example, where the pageview and radgrid are created with an AJAX call.
http://demos.telerik.com/aspnet-ajax/tabstrip/examples/multipage/dynamic-pageview-creation/defaultcs.aspx
http://demos.telerik.com/aspnet-ajax/tabstrip/examples/multipage/dynamic-pageview-creation/defaultcs.aspx
0

Shinu
Top achievements
Rank 2
answered on 13 May 2014, 07:09 AM
Hi Damian ,
The exporting feature of RadGrid work with regular postback only. The reason is the grid prepares additional information when performing export operation. When the action is performed through asynchronous requests, this information can not be passed through the XMLHttpObject - that is why the communication between the browser and the server fails.To bypass the limitation you can write the OnRequestStart event of the ajax panel or ajax manager, determine whether the target control is ajaxified and explicitly disable its ajax mode to export with regular postback as follows.
ASPX:
ASCX:
JavaScript:
C#:
Thanks,
Shinu.
The exporting feature of RadGrid work with regular postback only. The reason is the grid prepares additional information when performing export operation. When the action is performed through asynchronous requests, this information can not be passed through the XMLHttpObject - that is why the communication between the browser and the server fails.To bypass the limitation you can write the OnRequestStart event of the ajax panel or ajax manager, determine whether the target control is ajaxified and explicitly disable its ajax mode to export with regular postback as follows.
ASPX:
<
telerik:RadAjaxManager
runat
=
"server"
ID
=
"RadAjaxManager1"
EnablePageHeadUpdate
=
"true"
ClientEvents-OnRequestStart
=
"onRequestStart"
>
...
</
telerik:RadAjaxManager
>
ASCX:
<
telerik:RadGrid
ID
=
"RadGrid1"
runat
=
"server"
DataSourceID
=
"SqlDataSource1"
AutoGenerateColumns
=
"false"
>
<
MasterTableView
>
<
Columns
>
<
telerik:GridBoundColumn
DataField
=
"CustomerID"
UniqueName
=
"CustomerID"
>
</
telerik:GridBoundColumn
>
<
telerik:GridBoundColumn
DataField
=
"CompanyName"
UniqueName
=
"CompanyName"
>
</
telerik:GridBoundColumn
>
</
Columns
>
</
MasterTableView
>
</
telerik:RadGrid
>
<
telerik:RadButton
ID
=
"radbtnExport"
runat
=
"server"
Text
=
"ExportGrid"
OnClick
=
"RadButton1_Click"
>
</
telerik:RadButton
>
JavaScript:
function
onRequestStart(sender, args) {
if
(args.get_eventTarget().indexOf(
"radbtnExport"
) >= 0)
args.set_enableAjax(
false
);
}
C#:
protected
void
radbtnExport_Click(
object
sender, EventArgs e)
{
RadGrid1.MasterTableView.ExportToExcel();
}
Thanks,
Shinu.