This is what I'm trying to achieve:
I have some data that I want to export using a click of a button. When the user clicks the export button, I'm creating mutliple RadGrids dynamically, adding them to the form, and triggering the ExportToExcel() method.
This is part of the code:
When there is only ONE Grid created through this loop - everything works fine.
When there is more then one Grid created I'm getting an error:
Any clue on how to solve this matter?
I have some data that I want to export using a click of a button. When the user clicks the export button, I'm creating mutliple RadGrids dynamically, adding them to the form, and triggering the ExportToExcel() method.
This is part of the code:
For
Each
Vendor_ID
As
Integer
In
hashDataByVendor.Keys
Dim
tempRadGrid
As
New
Telerik.Web.UI.RadGrid
Dim
dtVendor_ID
As
System.Data.DataTable = hashDataByVendor(Vendor_ID)
tempRadGrid.DataSource = dtVendor_ID
Dim
vendor
As
New
Vendor(Vendor_ID)
tempRadGrid.ID =
String
.Format(
"{0}-{1}"
, vendor.Vendor_Name,
Date
.Now.ToString(
"MMddyyyy_HHmmssfff"
))
tempRadGrid.MasterTableView.Caption =
String
.Format(
"{0} ETA List for {1}"
, vendor.Vendor_Name,
Date
.Today.ToString(
"MM/dd/yyyy"
))
Dim
tempColumnGrid
As
New
Telerik.Web.UI.GridBoundColumn
tempRadGrid.MasterTableView.Columns.Add(tempColumnGrid)
tempColumnGrid.DataField =
"Task_ID"
tempColumnGrid.HeaderText =
"Task ID"
tempColumnGrid.ItemStyle.HorizontalAlign = HorizontalAlign.Left
tempRadGrid.MasterTableView.ShowHeader =
True
tempRadGrid.AutoGenerateColumns =
False
tempRadGrid.ExportSettings.HideStructureColumns =
False
tempRadGrid.ExportSettings.ExportOnlyData =
True
tempRadGrid.ExportSettings.FileName =
String
.Format(
"{0} - {1}"
, vendor.Vendor_Name,
Date
.Now)
tempRadGrid.ExportSettings.OpenInNewWindow =
True
Page.Controls.Add(tempRadGrid)
tempRadGrid.DataBind()
intTempVendor_ID = vendor.Vendor_ID
' Store the current vendor_id so we can use it in the GridExporting Sub.
tempRadGrid.MasterTableView.ExportToExcel()
AddHandler
tempRadGrid.GridExporting,
AddressOf
tempRadGrid_GridExporting
intVendorsCounter += 1
Next
When there is only ONE Grid created through this loop - everything works fine.
When there is more then one Grid created I'm getting an error:
The Controls collection cannot be modified because the control contains code blocks (i.e. <% ... %>).
Description: An unhandled exception occurred during
the execution of the current web request. Please review the stack trace
for more information about the error and where it originated in the
code.
Exception Details: System.Web.HttpException: The
Controls collection cannot be modified because the control contains code
blocks (i.e. <% ... %>).
Source Error:
Line 355: tempRadGrid.ExportSettings.FileName = String.Format("{0} - {1}", vendor.Vendor_Name, Date.Now)
Line 356: tempRadGrid.ExportSettings.OpenInNewWindow = True
Line 357: Page.Controls.Add(tempRadGrid)
Line 358: tempRadGrid.DataBind()
Line 359: intTempVendor_ID = vendor.Vendor_ID ' Store the current vendor_id so we can use it in the GridExporting Sub.
Line 355: tempRadGrid.ExportSettings.FileName = String.Format("{0} - {1}", vendor.Vendor_Name, Date.Now)
Line 356: tempRadGrid.ExportSettings.OpenInNewWindow = True
Line 357: Page.Controls.Add(tempRadGrid)
Line 358: tempRadGrid.DataBind()
Line 359: intTempVendor_ID = vendor.Vendor_ID ' Store the current vendor_id so we can use it in the GridExporting Sub.
Any clue on how to solve this matter?