I have been able to export to csv by adding a button to the CommandItemTemplate, then in server side findong the control and setting registerPostBackControl,
When fired this calls the export and fires correctly prompting the user to view or download.
However I have changed this to now appear as an item in the headerContextMenu, when the user clicks on the export option, the same code fires in the same order, however instead of exporting it just rebinds the data to the grid, the function i use is below,
Like i said boths methods in exporting call the same function, but only the contextItem will work. I am databinding the grid again as the user may have hidden some columns, so this way all coulmns are provided, also needed to remove the boundColumn.DataFormatString = "<nobr>{0:N}</nobr>"
which is created when the grid is loaded to prevent word wrap.
I create the headerMenuItems in the following way
The save Layout works fine (calls GridSettingsPersister)
Any help would be much appreciated.
Protected Sub RadGrid1_ItemCreated1(ByVal sender As Object, ByVal e As Telerik.Web.UI.GridItemEventArgs) Handles RadGrid1.ItemCreated .... Dim btn_excel As LinkButton = TryCast(item.FindControl("btn_excel"), LinkButton) ScriptManager.GetCurrent(Page).RegisterPostBackControl(btn_excel) ....End SubWhen fired this calls the export and fires correctly prompting the user to view or download.
However I have changed this to now appear as an item in the headerContextMenu, when the user clicks on the export option, the same code fires in the same order, however instead of exporting it just rebinds the data to the grid, the function i use is below,
Sub buildExport(ByVal type As String) RadGrid1.MasterTableView.Columns.Clear() Dim boundColumn As GridBoundColumn For Each column As DataColumn In Datasource.Columns If GridDataKeyNames <> "" Then If Not GridDataKeyNames.Contains(column.ColumnName.ToString()) Then If column.ColumnName.ToString().ToLower().IndexOf("_hidden") < 0 And column.ColumnName.ToString().ToLower().IndexOf("rowclick") < 0 Then boundColumn = New GridBoundColumn RadGrid1.MasterTableView.Columns.Add(boundColumn) boundColumn.DataField = column.ColumnName boundColumn.HeaderText = column.ColumnName.Replace("_", " ") Else boundColumn = New GridBoundColumn RadGrid1.MasterTableView.Columns.Add(boundColumn) boundColumn.DataField = column.ColumnName boundColumn.HeaderText = column.ColumnName boundColumn.Visible = False End If Else End If Else If column.ColumnName.ToString().ToLower().IndexOf("_hidden") < 0 And column.ColumnName.ToString().ToLower().IndexOf("rowclick") < 0 Then boundColumn = New GridBoundColumn RadGrid1.MasterTableView.Columns.Add(boundColumn) boundColumn.DataField = column.ColumnName boundColumn.HeaderText = column.ColumnName.Replace("_", " ").ToLower() Else boundColumn = New GridBoundColumn RadGrid1.MasterTableView.Columns.Add(boundColumn) boundColumn.DataField = column.ColumnName boundColumn.HeaderText = column.ColumnName.ToLower() boundColumn.Visible = False End If End If Next RadGrid1.DataSource = Datasource RadGrid1.DataBind() RadGrid1.PageSize = Datasource.Rows.Count() RadGrid1.ExportSettings.IgnorePaging = True Select Case type Case "excel" RadGrid1.ExportSettings.ExportOnlyData = True RadGrid1.MasterTableView.ExportToCSV() Case "pdf" RadGrid1.ExportSettings.OpenInNewWindow = True RadGrid1.MasterTableView.ExportToPdf() End Select End SubLike i said boths methods in exporting call the same function, but only the contextItem will work. I am databinding the grid again as the user may have hidden some columns, so this way all coulmns are provided, also needed to remove the boundColumn.DataFormatString = "<nobr>{0:N}</nobr>"
which is created when the grid is loaded to prevent word wrap.
I create the headerMenuItems in the following way
Private Sub addMenuItem(ByVal sender As Object, ByVal e As System.EventArgs) Dim menu As RadContextMenu = RadGrid1.HeaderContextMenu Dim item As New RadMenuItem item.Text = "Save Layout" item.Value = "save" item.Attributes("ColumnName") = String.Empty item.Attributes("TableID") = String.Empty menu.Items.Add(item) item = New RadMenuItem item.Attributes("ColumnName") = String.Empty item.Attributes("TableID") = String.Empty item.Text = "Export to CSV" item.Value = "csv" menu.Items.Add(item)End SubThe save Layout works fine (calls GridSettingsPersister)
Any help would be much appreciated.