This is a migrated thread and some comments may be shown as answers.

Export a Radgrid that is not visible

10 Answers 240 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Mark
Top achievements
Rank 1
Mark asked on 10 Apr 2015, 01:20 PM
I have a radgrid that is invisible and need to export it to excel.  It works great if I set the visible property to true but I don't want the user to see this grid as it is a combination of 2 grids that the user does see.

10 Answers, 1 is accepted

Sort by
0
Mark
Top achievements
Rank 1
answered on 10 Apr 2015, 01:21 PM

Here is the code I use to export:

rdgExport.DataSource = CType(Session("ExportReport"), DataTable)
rdgExport.DataBind()
rdgExport.MasterTableView.ExportToCSV()

0
Daniel
Telerik team
answered on 13 Apr 2015, 11:58 AM
Hello Mark,

Even if you set the Visible property to true in the export button handler, the control will still NOT be visible in the browser. The reason is that the current state is not persisted when exporting. You should be able to safely "show" the grid before export.

Regards,
Daniel
Telerik
 

See What's Next in App Development. Register for TelerikNEXT.

 
0
Mark
Top achievements
Rank 1
answered on 13 Apr 2015, 12:00 PM
Not sure what you mean by safely 'show' the grid before export? 
0
Daniel
Telerik team
answered on 13 Apr 2015, 01:10 PM
Hello Mark,

I mean that you can just display the otherwise hidden grid before exporting:
rdgExport.DataSource = CType(Session("ExportReport"), DataTable)
rdgExport.Visible = True
rdgExport.DataBind()
rdgExport.MasterTableView.ExportToCSV()

This operation should make it visible in the browser, but only in the exported file.

Regards,
Daniel
Telerik
 

See What's Next in App Development. Register for TelerikNEXT.

 
0
Mark
Top achievements
Rank 1
answered on 13 Apr 2015, 01:15 PM
I do need to hide it after so that doesn't seem to work.
0
Daniel
Telerik team
answered on 13 Apr 2015, 01:45 PM
Hello Mark,

I created a simple demo for you. It is a runnable (just add assemblies) website you could run at your side to test the behavior I mentioned.

Step by step:
- open the folder as Website in Visual Studio and then view it in the browser
- click on the export button
- check whether the RadGrid is visible in the browser

Please note that I don't explicitly hide the control afterwards.

Regards,
Daniel
Telerik
 

See What's Next in App Development. Register for TelerikNEXT.

 
0
Mark
Top achievements
Rank 1
answered on 13 Apr 2015, 02:05 PM

As I mentioned, that grid should not be displayed.  So maybe you might have another suggestion?  I have 2 datatables with the data.  I build 1 data table, then I need to add a row that is merged with some text that displays across all of the columns of that row as well as changing the background color.  Then I have a data table merge which merges other data with it.  So basically the grid should have:

1st data table data

merged row with text and background color

2nd data table data

I was able to get the text to display but I can't figure how to merge the cells of that row or change the background color.

 

0
Mark
Top achievements
Rank 1
answered on 13 Apr 2015, 02:06 PM

This is what I have so far that doesn't work:

Protected Sub rdgReels_ItemDataBound(sender As Object, e As Telerik.Web.UI.GridItemEventArgs) Handles rdgReels.ItemDataBound
If e.Item.Cells.Count > 2 Then
If e.Item.Cells(2).Text.StartsWith("Reels assigned") Then
Dim intCols = e.Item.Cells.Count
e.Item.Cells(0).BackColor = Drawing.Color.Yellow
e.Item.Cells(0).ColumnSpan = intCols
End If
End If
End Sub

0
Daniel
Telerik team
answered on 16 Apr 2015, 08:53 AM
Hello Mark,

Could you please confirm that you have tested (and not just examined) my example? As I mentioned below, the control will not be displayed at all using this approach. When exporting, the response of the asp.net request is substituted for the exported file and that original response never reaches the browser. The changes made on the server (like setting Visible="true") are not persisted and the control will not be shown in the browser at all.

As to your second question, I would recommend that you access the cells by the corresponding column name as shown below:
Protected Sub RadGrid1_ItemDataBound(sender As Object, e As GridItemEventArgs)
    Dim item As GridDataItem = TryCast(e.Item, GridDataItem)
    If item IsNot Nothing Then
        item("YourColumnUniqueName").BackColor = System.Drawing.Color.Yellow
    End If
End Sub

In the above example you have to replace "YourColumnUniqueName" with the real column name from your setup. Example:
<Columns>
    <telerik:GridBoundColumn UniqueName="YourColumnUniqueName" ... />
...


Although theoretically possible, I would suggest you avoid merging grid cells as this is not supported. Also when you (for example) change the colspan of a given cell to 2, you have to remove another cell from this column. You can also stumble across problems in some scenarios.

Regards,
Daniel
Telerik
 

See What's Next in App Development. Register for TelerikNEXT.

 
0
Mark
Top achievements
Rank 1
answered on 16 Apr 2015, 11:05 AM
I was able to get the color to work but isn't merging and splitting cells a in Excel, ASP.Net HTML etc. I have gone a different route as this control will not work for me.  Thank you for your time.
Tags
Grid
Asked by
Mark
Top achievements
Rank 1
Answers by
Mark
Top achievements
Rank 1
Daniel
Telerik team
Share this question
or