Hi,
I'm trying to export a grouped grid to excel. Only one issue left...
In RadGrid1_ItemDataBound I change the value of a column "totalseconds" from a number (92) to a string (1:32). Basically I'm converting seconds to a minute string. When I export to Excel, the column "totalseconds" spits out a bunch of zeros, instead of the updated value. The zeroes are not even the correct "original" values.
I think the question is... how do I maintain the updated value, from ItemDataBound, when exporting to Excel? I tried changing the value in ItemCreated and PreRender, but that didn't seem to work either. I have also tried everything in "Exporting Tips and Tricks" to no avail.
Here's the relevant code:
Any ideas?
Thanks,
Joe
I'm trying to export a grouped grid to excel. Only one issue left...
In RadGrid1_ItemDataBound I change the value of a column "totalseconds" from a number (92) to a string (1:32). Basically I'm converting seconds to a minute string. When I export to Excel, the column "totalseconds" spits out a bunch of zeros, instead of the updated value. The zeroes are not even the correct "original" values.
I think the question is... how do I maintain the updated value, from ItemDataBound, when exporting to Excel? I tried changing the value in ItemCreated and PreRender, but that didn't seem to work either. I have also tried everything in "Exporting Tips and Tricks" to no avail.
Here's the relevant code:
| <telerik:radgrid AllowSorting="true" AutoGenerateColumns="false" AllowFilteringByColumn="False" |
| AllowPaging="true" PageSize="20" id="RadGrid1" Skin="Gray" runat="server" OnExcelExportCellFormatting="RadGrid1_ExcelExportCellFormatting"> |
| <MasterTableView> |
| <GroupByExpressions> |
| <telerik:GridGroupByExpression> |
| <SelectFields> |
| <telerik:GridGroupByField FieldAlias="Activity" FieldName="daterounded" FormatString="{0:D}" HeaderValueSeparator=" from date: "></telerik:GridGroupByField> |
| </SelectFields> |
| <GroupByFields> |
| <telerik:GridGroupByField FieldName="daterounded" SortOrder="Descending"></telerik:GridGroupByField> |
| </GroupByFields> |
| </telerik:GridGroupByExpression> |
| </GroupByExpressions> |
| <SortExpressions> |
| <telerik:GridSortExpression FieldName="dateadded" SortOrder="Descending" /> |
| </SortExpressions> |
| <Columns> |
| <telerik:GridBoundColumn DataField="dateadded" UniqueName="dateadded" HeaderText="Activity Date (EST)" /> |
| <telerik:GridBoundColumn DataField="title" UniqueName="title" HeaderText="Lesson Title" /> |
| <telerik:GridBoundColumn DataField="status" UniqueName="status" HeaderText="Lesson Status" /> |
| <telerik:GridBoundColumn DataField="totalseconds" UniqueName="totalseconds" HeaderText="Total Time" /> |
| </Columns> |
| </MasterTableView> |
| </telerik:radgrid> |
| Private Sub RadGrid1_NeedDataSource(ByVal [source] As Object, ByVal e As Telerik.Web.UI.GridNeedDataSourceEventArgs)_ Handles RadGrid1.NeedDataSource |
| ' Populate RadGrid from DB |
| End Sub |
| Private Sub RadGrid1_ItemDataBound(ByVal sender As Object, ByVal e As Telerik.Web.UI.GridItemEventArgs) Handles RadGrid1.ItemDataBound |
| If TypeOf e.Item Is GridDataItem Then |
| Dim item As GridDataItem = e.Item |
| Dim totalseconds As Integer = CInt(item("totalseconds").Text) |
| Dim totaltime As String = formatTime(totalseconds) 'formatTime returns a string |
| item("totalseconds").Text = totaltime |
| End If |
| End Sub |
| Protected Sub btnExport_Click(ByVal sender As Object, ByVal e As System.Web.UI.ImageClickEventArgs) Handles btnExport.Click |
| RadGrid1.ExportSettings.ExportOnlyData = True |
| RadGrid1.ExportSettings.IgnorePaging = True |
| RadGrid1.ExportSettings.OpenInNewWindow = True |
| RadGrid1.MasterTableView.ExportToExcel() |
| End Sub |
Any ideas?
Thanks,
Joe