Hello there the RadGrid Export functionality is not working for me. Can you help what am I doing wrong?
Below is the aspx page code. I am trying to use btnExport to export to excel.
Below is the btnExport_Click:
In the btnSearch click event I fill in the grid. I tried with EnableViewState = true and/or with NeedDataSource where I fill the Grid again just in case while exporting it may need it. But nothing works.
Below is the aspx page code. I am trying to use btnExport to export to excel.
<%@ Page Language="C#" AutoEventWireup="true" MasterPageFile="~/MasterPage.Master"
CodeBehind="WorklistSummary.aspx.cs" Inherits="MyCompany.WorklistSummary"
MaintainScrollPositionOnPostback="true" %>
<
asp:Content
runat
=
"server"
ID
=
"Content1"
ContentPlaceHolderID
=
"cph1"
>
<
telerik:RadAjaxManagerProxy
runat
=
"server"
ID
=
"RadAjaxManagerProxy1"
>
<
AjaxSettings
>
<
telerik:AjaxSetting
AjaxControlID
=
"pnlMain"
>
<
UpdatedControls
>
<
telerik:AjaxUpdatedControl
ControlID
=
"pnlMain"
LoadingPanelID
=
"lp1"
/>
</
UpdatedControls
>
</
telerik:AjaxSetting
>
<
telerik:AjaxSetting
AjaxControlID
=
"btnSearch"
>
<
UpdatedControls
>
<
telerik:AjaxUpdatedControl
ControlID
=
"grdUserLoad"
LoadingPanelID
=
"lp1"
/>
</
UpdatedControls
>
</
telerik:AjaxSetting
>
<
telerik:AjaxSetting
AjaxControlID
=
"grdUserLoad"
>
<
UpdatedControls
>
<
telerik:AjaxUpdatedControl
ControlID
=
"grdUserLoad"
/>
</
UpdatedControls
>
</
telerik:AjaxSetting
>
</
AjaxSettings
>
</
telerik:RadAjaxManagerProxy
>
<
div
class
=
"formLayoutD"
>
<
asp:Panel
runat
=
"server"
ID
=
"pnlMain"
Height
=
"99%"
Width
=
"100%"
>
<
h3
>
Worklist Summary</
h3
>
<
asp:ValidationSummary
ID
=
"valSummary"
runat
=
"server"
DisplayMode
=
"BulletList"
CssClass
=
"validationSummary"
ShowSummary
=
"true"
ValidationGroup
=
"DateNeeded"
/>
<
table
width
=
"450px"
>
<
tr
style
=
"border: 1; border-color: black; border-width: 2"
>
<
td
style
=
"width: 20%; text-align: left"
>
Admit Date Between:
</
td
>
<
td
style
=
"width: 35%"
>
<
telerik:RadDatePicker
ID
=
"dpStartAdmitDate"
runat
=
"server"
AutoPostBack
=
"false"
Calendar
=
""
Width
=
"100px"
>
<
Calendar
ID
=
"Calendar1"
ShowRowHeaders
=
"False"
runat
=
"server"
/>
</
telerik:RadDatePicker
>
<
asp:RequiredFieldValidator
ID
=
"valdpStartAdmitDate1"
runat
=
"server"
ControlToValidate
=
"dpStartAdmitDate"
ValidationGroup
=
"DateNeeded"
SetFocusOnError
=
"true"
ErrorMessage
=
"Start Date is required"
Display
=
"None"
Text
=
""
/>
And
<
telerik:RadDatePicker
ID
=
"dpEndAdmitDate"
runat
=
"server"
AutoPostBack
=
"false"
Width
=
"100px"
>
<
Calendar
ID
=
"Calendar2"
ShowRowHeaders
=
"False"
runat
=
"server"
/>
</
telerik:RadDatePicker
>
<
asp:RequiredFieldValidator
ID
=
"valdpEndAdmitDate1"
runat
=
"server"
ControlToValidate
=
"dpEndAdmitDate"
ValidationGroup
=
"DateNeeded"
SetFocusOnError
=
"true"
ErrorMessage
=
"End Date is required"
Display
=
"None"
Text
=
""
/>
</
td
>
<
td
style
=
"width: 5%;"
align
=
"left"
>
<
asp:Button
runat
=
"server"
ID
=
"btnSearch"
Text
=
"Search"
Width
=
"75px"
ValidationGroup
=
"DateNeeded"
OnClick
=
"btnSearch_Click"
/>
</
td
>
<
td
style
=
"width: 5%;"
align
=
"left"
>
<
asp:Button
runat
=
"server"
ID
=
"btnExport"
Text
=
"Export"
Width
=
"75px"
OnClick
=
"btnExport_Click"
/>
</
td
>
</
tr
>
</
table
>
<
div
>
<
telerik:RadGrid
ID
=
"grdUserLoad"
runat
=
"server"
AutoGenerateColumns
=
"False"
CssClass
=
"Grid"
Skin
=
"Windows7"
GridLines
=
"Vertical"
Width
=
"80%"
AllowMultiRowSelection
=
"false"
AllowFilteringByColumn
=
"False"
AllowSorting
=
"false"
AllowPaging
=
"True"
PageSize
=
"20"
OnNeedDataSource
=
"grdUserLoad_OnNeedDataSource"
>
<
ExportSettings
HideStructureColumns
=
"True"
IgnorePaging
=
"True"
ExportOnlyData
=
"True"
/>
<
MasterTableView
Width
=
"100%"
EnableViewState
=
"True"
>
<
GroupByExpressions
>
<
telerik:GridGroupByExpression
runat
=
"server"
>
<
SelectFields
>
<
telerik:GridGroupByField
runat
=
"server"
FieldName
=
"Name"
HeaderText
=
"User Name"
/>
</
SelectFields
>
<
GroupByFields
>
<
telerik:GridGroupByField
runat
=
"server"
FieldName
=
"Name"
HeaderText
=
""
SortOrder
=
"Ascending"
/>
</
GroupByFields
>
</
telerik:GridGroupByExpression
>
</
GroupByExpressions
>
<
RowIndicatorColumn
>
<
HeaderStyle
Width
=
"10px"
></
HeaderStyle
>
</
RowIndicatorColumn
>
<
ExpandCollapseColumn
>
<
HeaderStyle
Width
=
"10px"
></
HeaderStyle
>
</
ExpandCollapseColumn
>
<
Columns
>
<
telerik:GridBoundColumn
HeaderText
=
"User"
DataField
=
"Name"
UniqueName
=
"UserName"
Visible
=
"False"
/>
<
telerik:GridBoundColumn
HeaderText
=
"Group(s)"
DataField
=
"ParentName"
UniqueName
=
"GroupName"
/>
<
telerik:GridBoundColumn
HeaderText
=
"Workload"
DataField
=
"CountAccount"
UniqueName
=
"CountAccount"
/>
</
Columns
>
</
MasterTableView
>
<
HeaderStyle
CssClass
=
"GridHeader"
/>
<
PagerStyle
AlwaysVisible
=
"False"
Mode
=
"NextPrevAndNumeric"
HorizontalAlign
=
"Center"
Height
=
"35px"
></
PagerStyle
>
<
GroupingSettings
CaseSensitive
=
"False"
/>
</
telerik:RadGrid
>
</
div
>
</
asp:Panel
>
</
div
>
</
asp:Content
>
Below is the btnExport_Click:
protected
void
btnExport_Click(
object
sender, EventArgs e)
{
grdUserLoad.MasterTableView.ExportToExcel();
}
In the btnSearch click event I fill in the grid. I tried with EnableViewState = true and/or with NeedDataSource where I fill the Grid again just in case while exporting it may need it. But nothing works.