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

Exporting TextBoxes

5 Answers 240 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Rob
Top achievements
Rank 1
Rob asked on 22 Jun 2011, 04:48 PM
I'm looking at your online demo for Exporting from the RadGrid.

http://demos.telerik.com/aspnet-ajax/grid/examples/generalfeatures/exporting/defaultcs.aspx

I immediately click on the "Export to Excel" button.  While reviewing the exported Excel or Word file, I notice that each textbox in the grid's footer has replicated itself 3 times for Page where I believe it should only display once.  Please see attached screenshot (exportexcel.jpg).

I am experiencing something similar when exporting a RadGrid to Excel with a RadTextbox visible on a grid row.  Please see screenshot of grid before exporting (exportgrid.jpg).  Please see screenshot of exported data (exportedtextbox.jpg). I'm my example, the textbox & value are duplicated.

My grid column is defined like this:

<telerik:GridTemplateColumn UniqueName="colUnits" HeaderText="Units">
   <HeaderStyle Width="100px" HorizontalAlign="Left" />
   <ItemStyle Width="100px" HorizontalAlign="Right" />
   <ItemTemplate>
      <telerik:RadNumericTextBox ID="txtUnits" runat="server" Width="40px" AutoPostBack="false"
         NumberFormat-DecimalDigits="0" CausesValidation="false" MinValue="0" MaxLength="3"
         NumberFormat-AllowRounding="false" Style="text-align:right;">
          <ClientEvents OnValueChanged="txtUnits_OnValueChanged" />
          <ClientEvents OnKeyPress="KeyPress" />
      </telerik:RadNumericTextBox>
   </ItemTemplate>
</telerik:GridTemplateColumn>

The grid is NOT in edit mode and I would like to just export the data inside the textbox. 

When I attempt to do the following setting:

grid.ExportSettings.ExportOnlyData = True

The column with the textbox does not get any data exported at all to Excel or PDF.

If

grid.ExportSettings.ExportOnlyData = False

Then I get the issue described above with the replicated data when exporting to Excel.  Still no data get exported for PDF.

I believe this is either an export setting issue, a formatting issue, or a bug with the export functionality.

Please advise.

5 Answers, 1 is accepted

Sort by
0
Rob
Top achievements
Rank 1
answered on 23 Jun 2011, 02:41 PM
Any help with this would be great. Thanks.
0
Rob
Top achievements
Rank 1
answered on 24 Jun 2011, 04:07 PM
Here is the simplest code to reproduce the issue:

<%@ Page Language="VB" AutoEventWireup="false" CodeFile="Default.aspx.vb" Inherits="_Default" %>
<%@ Register Assembly="Telerik.Web.UI" Namespace="Telerik.Web.UI" TagPrefix="telerik" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<head runat="server">
    <title></title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <telerik:RadScriptManager ID="RadScriptManager1" runat="server">
        </telerik:RadScriptManager>
        <telerik:RadGrid ID="RadGrid1" runat="server" AutoGenerateColumns="false">
            <MasterTableView>
                <Columns>
                    <telerik:GridBoundColumn DataField="SIZE" HeaderText="Size"></telerik:GridBoundColumn>
                    <telerik:GridTemplateColumn HeaderText="Units">
                        <ItemTemplate>
                            <telerik:RadNumericTextBox ID="txtUnits" runat="server" Value="20"></telerik:RadNumericTextBox>
                        </ItemTemplate>
                    </telerik:GridTemplateColumn>
                </Columns>
            </MasterTableView>
        </telerik:RadGrid>
        <asp:Button ID="btn" runat="server" Text="Export" />
    </div>
    </form>
</body>
</html>
Imports System.Data
  
Partial Class _Default
    Inherits System.Web.UI.Page
  
    Protected Sub btn_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btn.Click
        RadGrid1.ExportSettings.OpenInNewWindow = True
        RadGrid1.ExportSettings.ExportOnlyData = False
        RadGrid1.MasterTableView.UseAllDataFields = True
        RadGrid1.MasterTableView.ExportToExcel()
    End Sub
  
    Protected Sub RadGrid1_NeedDataSource(ByVal source As Object, ByVal e As Telerik.Web.UI.GridNeedDataSourceEventArgs) Handles RadGrid1.NeedDataSource
        Dim dt As New datatable
        Dim col As New DataColumn("SIZE")
        dt.Columns.Add(col)
        Dim dr As DataRow = dt.NewRow
        dr(0) = "S"
        dt.Rows.Add(dr)
        dr = dt.NewRow
        dr(0) = "M"
        dt.Rows.Add(dr)
        dr = dt.NewRow
        dr(0) = "L"
        dt.Rows.Add(dr)
        RadGrid1.DataSource = dt
    End Sub
End Class

Run the code & click the Export button. You should see the same as attached screen shot exportedunits.jpg where the values in the textboxes are displayed 3 times in the units column. I need to figure out how to only display the textbox value once per row.  Textbox values don't render at all when exporting to PDF.  I had to parse out the rawHTML to get textbox values extracted in order to rewrite the HTML to display in the PDF. I would like to do something similar when exporting to Excel.
0
Daniel
Telerik team
answered on 28 Jun 2011, 04:06 PM
Hello,

RadNumericTextBox consists of three inputs (only one of them is visible) - thence this behavior. A possible approach (if you need ExportOnlyData to be false) to sidestep this is to get the control value and put it directly to the table cell - this will clear the controls collection.
Private isExport As Boolean = False
Protected Sub btn_Click(sender As Object, e As System.EventArgs) Handles btn.Click
    RadGrid1.ExportSettings.OpenInNewWindow = True
    RadGrid1.ExportSettings.ExportOnlyData = False
    RadGrid1.MasterTableView.UseAllDataFields = True
    isExport = True
    If RadGrid1.ExportSettings.IgnorePaging = False Then
        RadGrid1.Rebind()
    End If
    RadGrid1.MasterTableView.ExportToExcel()
End Sub


Protected Sub RadGrid1_ItemDataBound(sender As Object, e As GridItemEventArgs) Handles RadGrid1.ItemDataBound
    If isExport AndAlso TypeOf e.Item Is GridDataItem Then
        Dim rntb As RadNumericTextBox = TryCast(e.Item.FindControl("txtUnits"), RadNumericTextBox)
        TryCast(rntb.Parent, TableCell).Text = rntb.Text
    End If
End Sub

Regards,
Daniel
the Telerik team

Browse the vast support resources we have to jump start your development with RadControls for ASP.NET AJAX. See how to integrate our AJAX controls seamlessly in SharePoint 2007/2010 visiting our common SharePoint portal.

0
Rob
Top achievements
Rank 1
answered on 06 Jul 2011, 05:22 PM
That did the trick! Thanks you!

Can you answer another question for me?  When I change some grid appearance settings like formatting the header, etc before rebinding the grid then exporting the data, how is it that the data/grid appearance getting exported is formatted, but the grid on the screen does not reformat after the rebind?
0
Daniel
Telerik team
answered on 08 Jul 2011, 09:50 PM
Hello,

The response is redirected to the exported file - the content from this response won't reach the browser (it will be sent as a file) and thus all changes you have made will be lost.

Best regards,
Daniel
the Telerik team

Register for the Q2 2011 What's New Webinar Week. Mark your calendar for the week starting July 18th and book your seat for a walk through of all the exciting stuff we will ship with the new release!

Tags
Grid
Asked by
Rob
Top achievements
Rank 1
Answers by
Rob
Top achievements
Rank 1
Daniel
Telerik team
Share this question
or