10 Answers, 1 is accepted
Here is the code I use to export:
rdgExport.DataSource = CType(Session("ExportReport"), DataTable)
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.
I mean that you can just display the otherwise hidden grid before exporting:
This operation should make it visible in the browser, but only in the exported file.
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.
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
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:
In the above example you have to replace "YourColumnUniqueName" with the real column name from your setup. Example:
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.