Hi,
I am using Telerik Controls version 2015.1.401.40
I am trying to Export Grid data to excel. But nothing happening
Here is my code
<
telerik:RadAjaxManager
ID
=
"RadAjaxManager1"
runat
=
"server"
>
<
ClientEvents
OnRequestStart
=
"onRequestStart"
/>
<
AjaxSettings
>
<
telerik:AjaxSetting
AjaxControlID
=
"Grid1"
>
<
UpdatedControls
>
<
telerik:AjaxUpdatedControl
ControlID
=
"Grid1"
/>
</
UpdatedControls
>
</
telerik:AjaxSetting
>
</
AjaxSettings
>
</
telerik:RadAjaxManager
>
<
telerik:RadGrid
ID
=
"Grid1"
runat
=
"server"
AllowPaging
=
"true"
AllowSorting
=
"true"
Width
=
"100%"
Height
=
"100%"
AllowFilteringByColumn
=
"true"
Skin
=
"Bootstrap"
AutoGenerateColumns
=
"false"
PageSize
=
"25"
AllowMultiRowSelection
=
"true"
OnNeedDataSource
=
"Grid1_NeedDataSource"
OnItemCommand
=
"Grid1_ItemCommand"
>
<
HeaderStyle
HorizontalAlign
=
"Left"
Font-Bold
=
"true"
Font-Size
=
"10pt"
></
HeaderStyle
>
<
GroupingSettings
CaseSensitive
=
"false"
/>
<
MasterTableView
Name
=
"Master"
Width
=
"100%"
>
<
PagerStyle
Position
=
"Bottom"
PageSizeControlType
=
"RadDropDownList"
Mode
=
"NextPrevNumericAndAdvanced"
ShowPagerText
=
"true"
PageSizes
=
"25,50,100,200"
/>
<
Columns
>
<
telerik:GridClientSelectColumn
UniqueName
=
"ClientSelectColumn"
>
<
HeaderStyle
HorizontalAlign
=
"Left"
Width
=
"25px"
></
HeaderStyle
>
<
ItemStyle
HorizontalAlign
=
"Left"
Width
=
"25px"
></
ItemStyle
>
</
telerik:GridClientSelectColumn
>
<
telerik:GridBoundColumn
DataField
=
"Name"
HeaderText
=
"Name"
AllowFiltering
=
"false"
>
<
HeaderStyle
HorizontalAlign
=
"Left"
Wrap
=
"false"
></
HeaderStyle
>
<
ItemStyle
HorizontalAlign
=
"Left"
Wrap
=
"true"
></
ItemStyle
>
</
telerik:GridBoundColumn
>
<
telerik:GridBoundColumn
DataField
=
"Address"
HeaderText
=
"Address"
AllowFiltering
=
"false"
>
<
HeaderStyle
HorizontalAlign
=
"Left"
Wrap
=
"false"
></
HeaderStyle
>
<
ItemStyle
HorizontalAlign
=
"Left"
Wrap
=
"true"
></
ItemStyle
>
</
telerik:GridBoundColumn
>
<
telerik:GridBoundColumn
DataField
=
"E-Mail"
HeaderText
=
"E-Mail"
AllowFiltering
=
"false"
>
<
HeaderStyle
HorizontalAlign
=
"Left"
Wrap
=
"false"
></
HeaderStyle
>
<
ItemStyle
HorizontalAlign
=
"Left"
Wrap
=
"false"
></
ItemStyle
>
</
telerik:GridBoundColumn
>
<
telerik:GridBoundColumn
DataField
=
"Phone"
HeaderText
=
"Phone"
AllowFiltering
=
"false"
>
<
HeaderStyle
HorizontalAlign
=
"Left"
Wrap
=
"false"
></
HeaderStyle
>
<
ItemStyle
HorizontalAlign
=
"Left"
Wrap
=
"true"
></
ItemStyle
>
</
telerik:GridBoundColumn
>
</
Columns
>
</
MasterTableView
>
<
ClientSettings
>
</
ClientSettings
>
</
telerik:RadGrid
>
on my ASPX.cs page
protected void Grid1_ItemCommand(object sender, GridCommandEventArgs e)
{
try
{
switch (e.CommandName)
{
case "ExportToExcel":
GridLeads.GridLines = GridLines.Both;
GridLeads.MasterTableView.GridLines = GridLines.Both;
GridLeads.MasterTableView.HeaderStyle.BackColor = System.Drawing.Color.LightGray;
GridLeads.MasterTableView.ItemStyle.BackColor = System.Drawing.Color.LightYellow;
GridLeads.MasterTableView.AlternatingItemStyle.BackColor = System.Drawing.Color.LightYellow;
GridLeads.Columns.FindByUniqueName("ClientSelectColumn").Visible = false;
GridLeads.MasterTableView.AllowFilteringByColumn = false;
GridLeads.MasterTableView.PagerStyle.Position = GridPagerPosition.Bottom;
GridLeads.ExportSettings.ExportOnlyData = true;
GridLeads.ExportSettings.OpenInNewWindow = true;
GridLeads.ExportSettings.IgnorePaging = true;
GridLeads.ExportSettings.FileName = "Lead(s) Report";
GridLeads.MasterTableView.ExportToExcel();
break;
}
}
catch (Exception ex)
{
throw new Exception("Error While Loading Grid ItemCommand", ex);
}
}
my ASPX page
<
asp:Button
ID
=
"btnExport"
runat
=
"server"
OnClientClick
=
"ExportToExcel();return false;"
ToolTip
=
"Export To Excel"
class
=
"btn btn-default btn-sm"
Text
=
"Export"
/>
<
telerik:RadCodeBlock
ID
=
"RadCodeBlock1"
runat
=
"server"
>
<
script
type
=
"text/javascript"
>
function onRequestStart(sender, args) {
if (args.get_eventTarget().indexOf("btnExport") >= 0)
{
args.set_enableAjax(false);
}
}
function ExportToExcel() {
$find('<%= Grid1.ClientID %>').get_masterTableView().fireCommand("ExportToExcel");
}
</script>
</telerik:RadCodeBlock>