10 Answers, 1 is accepted

Here is the code I use to export:
rdgExport.DataSource = CType(Session("ExportReport"), DataTable)
rdgExport.DataBind()
rdgExport.MasterTableView.ExportToCSV()
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.

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.

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.

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.

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
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.
