I need to export my RadGrid, which displays correctly, to an Excel file. But when I click the Export To Excel button, it doesn't export. Instead, the entire Command Item bar disappears.
The same thing is happening on another RadGrid on the same page, but clicking the Export To Excel button also removes paging from the RadGrid, so that it displays all of the data.
Here is the markup for the second RadGrid:
<telerik:RadGrid ID="rgPickedDetail" runat="server" AllowFilteringByColumn="False" AllowPaging="True" OnItemCommand="rgPickedDetail_ItemCommand"
AllowSorting="True" DataSourceID="DetailDataSource" ShowStatusBar="True" PageSize="15" OnItemDataBound="rgPickedDetail_ItemDataBound"
Skin="Telerik" AllowAutomaticUpdates="true" AutoGenerateColumns="False">
<ExportSettings HideStructureColumns="true" Excel-Format="Xlsx" ExportOnlyData="true" IgnorePaging="true" />
<PagerStyle Mode="NextPrevNumericAndAdvanced"></PagerStyle>
<MasterTableView CommandItemDisplay="Top" HierarchyLoadMode="ServerOnDemand" AllowSorting="false" AutoGenerateColumns="false">
<CommandItemSettings ShowExportToCsvButton="true" ShowExportToExcelButton="true" ShowAddNewRecordButton="false" ShowRefreshButton="true" />
<Columns>
<telerik:GridBoundColumn DataField="Plant" DataType="System.String" HeaderText="Plant" ReadOnly="True" UniqueName="Plant" />
<telerik:GridBoundColumn DataField="PartNum" DataType="System.String" HeaderText="Part" ReadOnly="True" UniqueName="PartNum" />
<telerik:GridBoundColumn DataField="SerialNum" DataType="System.String" HeaderText="Serial number" ReadOnly="True" UniqueName="SerialNum" />
<telerik:GridBoundColumn DataField="QtyPicked" DataType="System.Int32" HeaderText="Picked" ReadOnly="True" UniqueName="QtyPicked" />
<telerik:GridBoundColumn DataField="QtyReq" DataType="System.Int32" HeaderText="Requested" ReadOnly="True" UniqueName="QtyReq" />
<telerik:GridBoundColumn DataField="Scanned" DataType="System.DateTime" DataFormatString="{0:M/d/yy HH:mm}" HeaderText="Scanned" ReadOnly="True" UniqueName="Scanned" />
<telerik:GridBoundColumn DataField="FromLoc" DataType="System.String" HeaderText="From" ReadOnly="True" UniqueName="FromLoc" />
<telerik:GridBoundColumn DataField="ToLoc" DataType="System.String" HeaderText="To" ReadOnly="True" UniqueName="ToLoc" />
<telerik:GridBoundColumn DataField="Picked" DataType="System.Boolean" Display="false" HeaderText="Picked (invisible)" UniqueName="Picked" />
</Columns>
</MasterTableView>
</telerik:RadGrid>
Here is the relevant code-behind:
Shared ReportDate As Date
Protected Sub Page_Load(sender As Object, e As EventArgs) Handles Me.Load
If ReportDate = Nothing Then
ReportDate = Today
StartDate.SelectedDate = ReportDate
End If
SetReportDate()
If Not Page.IsPostBack Then
End If
End Sub
Protected Sub MessageBox(msg As String)
ScriptManager.RegisterStartupScript(Me, Me.GetType, "WindowsScript", "alert('" + msg + "');", True)
End Sub
Protected Sub rgPickedDetail_ItemDataBound(sender As Object, e As GridItemEventArgs)
If e.Item.GetType() Is GetType(GridDataItem) Then
Dim item As GridDataItem = e.Item
item.ForeColor = IIf(item("Picked").Text = "True", Color.Green, Color.Red)
End If
End Sub
Protected Sub StartDate_SelectedDateChanged(sender As Object, e As Calendar.SelectedDateChangedEventArgs)
ReportDate = e.NewDate
SetReportDate()
rgPickedSummary.Rebind()
rgPickedDetail.Rebind()
End Sub
Private Sub SetReportDate()
SummaryDataSource.SelectParameters("StartDate").DefaultValue = ReportDate
DetailDataSource.SelectParameters("StartDate").DefaultValue = ReportDate
End Sub
Protected Sub rgPickedDetail_ItemCommand(sender As Object, e As GridCommandEventArgs)
If e.CommandName = "ExportToExcel" Then
rgPickedDetail.Rebind()
End If
End Sub
Protected Sub rgPickedDetail_ItemCreated(sender As Object, e As GridItemEventArgs) Handles rgPickedDetail.ItemCreated
If TypeOf e.Item Is GridCommandItem Then
ScriptManager.GetCurrent(Page).RegisterPostBackControl(e.Item.FindControl("ExportToExcelButton"))
End If
End Sub
Protected Sub rgPickedSummary_ItemCreated(sender As Object, e As GridItemEventArgs) Handles rgPickedSummary.ItemCreated
If TypeOf e.Item Is GridCommandItem Then
ScriptManager.GetCurrent(Page).RegisterPostBackControl(e.Item.FindControl("ExportToExcelButton"))
End If
End Sub
Hi Lee,
I have reviewed the provided code and I was not able to see any obvious reason for the described behavior.
Please make sure there are no JavaScript errors on the Browser's Console:
I have used the provided RadGrid declaration to create a basic sample with some dummy data and the behavior on my end is the expected one, see http://somup.com/c0iZjKzC0y
I am attaching the project I used for testing so you can give it a try too. You will need to add all the required Telerik assemblies in the bin folder to run the project. It would be very helpful if you modify the sample page in a way it leads to the same problem and let me know so I can replicate the problem on my end