I have a radgrid that gets populated on the server side after a user enters in some parameters, and clicks the search button. I have a radajaxmanager that updates the radgrid when button 1 is pushed. (See code below.)
I tried to copy from the export demo how to use the command item buttons to export the radgrid to pdf/word/excel etc. However, it is not exporting. I put a breakpoint on the function called "RadGrid1_ItemCommand". This function DOES get called when I click on an export button, and the if e.command statement does go to the correct export option I want. (Ex. ExportToExcel). However, when the program gets to the line: RadGrid1.MasterTableView.ExportToExcel(), nothing happens. Am I missing some code?
Here's what I have so far.
Asp part
VB part
Thanks,
GP
I tried to copy from the export demo how to use the command item buttons to export the radgrid to pdf/word/excel etc. However, it is not exporting. I put a breakpoint on the function called "RadGrid1_ItemCommand". This function DOES get called when I click on an export button, and the if e.command statement does go to the correct export option I want. (Ex. ExportToExcel). However, when the program gets to the line: RadGrid1.MasterTableView.ExportToExcel(), nothing happens. Am I missing some code?
Here's what I have so far.
Asp part
| <%@ Register Assembly="Telerik.Web.UI" Namespace="Telerik.Web.UI" TagPrefix="telerik" %> |
| <div> |
| <telerik:RadScriptManager ID="RadScriptManager1" runat="server" AsyncPostBackTimeout="600"> |
| </telerik:RadScriptManager> |
| <telerik:RadGrid ID="RadGrid1" runat="server" Skin="Sunset" AllowSorting="True" |
| GridLines="None" Width="95%" OnItemCommand="RadGrid1_ItemCommand"> |
| <MasterTableView CommandItemDisplay="Top"> |
| <RowIndicatorColumn> |
| <HeaderStyle Width="20px"></HeaderStyle> |
| </RowIndicatorColumn> |
| <ExpandCollapseColumn> |
| <HeaderStyle Width="20px"></HeaderStyle> |
| </ExpandCollapseColumn> |
| <CommandItemSettings |
| ShowExportToWordButton="true" |
| ShowExportToExcelButton="true" |
| ShowExportToCsvButton="true" |
| ShowExportToPdfButton="true" |
| /> |
| </MasterTableView> |
| </telerik:RadGrid> |
| </div> |
| <script type="text/javascript"> |
| function onRequestStart(sender, args) |
| { |
| if (args.get_eventTarget().indexOf("ExportToExcelButton") >= 0 || |
| args.get_eventTarget().indexOf("ExportToWordButton") >= 0 || |
| args.get_eventTarget().indexOf("ExportToPdfButton") >= 0 || |
| args.get_eventTarget().indexOf("ExportToCsvButton") >= 0) |
| { |
| args.set_enableAjax(false); |
| } |
| } |
| </script> |
| <telerik:RadAjaxManager runat="server"> |
| <ClientEvents OnRequestStart="onRequestStart" /> |
| <AjaxSettings> |
| <telerik:AjaxSetting AjaxControlID="Button1"> |
| <UpdatedControls> |
| <telerik:AjaxUpdatedControl ControlID="RadGrid1" LoadingPanelID="RadAjaxLoadingPanel1" /> |
| </UpdatedControls> |
| </telerik:AjaxSetting> |
| </AjaxSettings> |
| </telerik:RadAjaxManager> |
| <telerik:RadAjaxLoadingPanel ID="RadAjaxLoadingPanel1" runat="server" Height="75px" |
| Width="75px" Skin="Forest"> |
| </telerik:RadAjaxLoadingPanel> |
VB part
| Imports Telerik.Web.UI |
| Imports Telerik.Web.UI.Common |
| Imports Telerik.Web.UI.Grid |
| Imports Telerik.Web.UI.RadGrid |
| Protected Sub Button1_Click(ByVal sender As Object, ByVal e As EventArgs) Handles Button1.Click |
| Dim sqlString As String |
| sqlString = "my params" |
| RadGrid1.DataSource = ws1.getData(sqlString).Tables("DAT") |
| RadGrid1.DataBind() |
| Dim cmdItem As GridCommandItem |
| cmdItem = RadGrid1.MasterTableView.GetItems(GridItemType.CommandItem)(0) |
| cmdItem.FindControl("InitInsertButton").Visible = False |
| cmdItem.FindControl("AddNewRecordButton").Visible = False |
| cmdItem.FindControl("RebindGridButton").Visible = False |
| cmdItem.FindControl("RefreshButton").Visible = False |
| End Sub |
| Protected Sub RadGrid1_ItemCommand(ByVal sender As Object, ByVal e As Telerik.Web.UI.GridCommandEventArgs) |
| If e.CommandName = Telerik.Web.UI.RadGrid.ExportToExcelCommandName Then |
| RadGrid1.ExportSettings.OpenInNewWindow = True |
| RadGrid1.MasterTableView.ExportToExcel() |
| ElseIf e.CommandName = Telerik.Web.UI.RadGrid.ExportToWordCommandName Then |
| RadGrid1.ExportSettings.OpenInNewWindow = True |
| RadGrid1.MasterTableView.ExportToWord() |
| ElseIf e.CommandName = Telerik.Web.UI.RadGrid.ExportToCsvCommandName Then |
| RadGrid1.ExportSettings.OpenInNewWindow = True |
| RadGrid1.MasterTableView.ExportToCSV() |
| ElseIf e.CommandName = Telerik.Web.UI.RadGrid.ExportToPdfCommandName Then |
| RadGrid1.ExportSettings.OpenInNewWindow = True |
| RadGrid1.MasterTableView.ExportToPdf() |
| End If |
| End Sub |
Thanks,
GP