Export to excel from RadGrid is blank when binded using dynamically through vb code

9 posts, 0 answers
  1. Kavita
    Kavita avatar
    39 posts
    Member since:
    Feb 2013

    Posted 25 Sep 2013 Link to this post

    Hi,
    I have a search form , in which user fills information.
    Is is not compulsory to fill all the information, so whatever user has filled according to that i show the result in my RadGrid.

    My query looks like this.

    Dim connection As SqlConnection =
    New SqlConnection(ConfigurationManager.ConnectionStrings("InductoServConnectionString").ToString())
                connection.Open()

                cmd = New SqlCommand("select * from tblServiceReports where " + Condition, connection)

                myReader = cmd.ExecuteReader()

                gdCstRecovery.DataSource = myReader

    Here "condition" is a variable which contains parameters.

    When radgrid shows the result, i try to export it using provided button Export to Excel in ExcelML format.
    But excel is coming blank. No column or any data is present.
    Please help. It is quite urgent.
       
  2. Princy
    Princy avatar
    17421 posts
    Member since:
    Mar 2007

    Posted 25 Sep 2013 Link to this post

    Hi ,

    Please try to enable UseAllDataFields property in MasterTableView:

    ASPX:
    <MasterTableView UseAllDataFields="true" ... >
     
    If this doesn't help,please provide your full code snippet.

    Thanks,
    Princy
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Kavita
    Kavita avatar
    39 posts
    Member since:
    Feb 2013

    Posted 26 Sep 2013 Link to this post

    I am showing footer in grid for one column to show its total.
    When i use <MasterTableView UseAllDataFields="true" ... > , my total footer does not get displayed in Excel.
  5. Princy
    Princy avatar
    17421 posts
    Member since:
    Mar 2007

    Posted 26 Sep 2013 Link to this post

    Hi Kavitha,

    Please try the sample code snippet to export footer to excel.

    ASPX:
    <asp:Button ID="Button1" runat="server" Text="Export" OnClick="Button1_Click" />
    <telerik:RadGrid ID="RadGrid1" runat="server" OnNeedDataSource="RadGrid1_NeedDataSource"
        Width="600px" OnExcelMLExportRowCreated="RadGrid1_ExcelMLExportRowCreated">
        <ExportSettings ExportOnlyData="true" Excel-Format="ExcelML" />
        <MasterTableView AutoGenerateColumns="false" ShowFooter="true">
            <Columns>
                <telerik:GridBoundColumn Aggregate="Count" DataField="ProductName" FooterAggregateFormatString="Total products: {0}" />
                <telerik:GridBoundColumn Aggregate="Sum" DataField="Price" FooterAggregateFormatString="Total: {0}" />
                <telerik:GridBoundColumn DataField="Manufacturer" />
            </Columns>
        </MasterTableView>
    </telerik:RadGrid>

    C#:
    protected void RadGrid1_NeedDataSource(object source, GridNeedDataSourceEventArgs e)
       {
           DataTable table = new DataTable();
           table.Columns.Add("ProductName");
           table.Columns.Add("Price", typeof(double));
           table.Columns.Add("Manufacturer");
     
           table.Rows.Add("Futo maki", 12.44, "Osaka Nihonbashi");
           table.Rows.Add("Musaka", 10.61, "Sofiiski gozbi");
           table.Rows.Add("Cheesezer", 9.50, "Burger mafia");
     
           RadGrid1.DataSource = table;
       }
     
       protected void RadGrid1_ExcelMLExportRowCreated(object source, GridExportExcelMLRowCreatedArgs e)
       {
           if (e.Worksheet.Table.Rows.Count == RadGrid1.Items.Count + 1)
           {
               RowElement row = new RowElement();
               GridFooterItem footer = (source as RadGrid).MasterTableView.GetItems(GridItemType.Footer)[0] as GridFooterItem;
               foreach (GridColumn column in (source as RadGrid).MasterTableView.Columns)
               {
                   CellElement cell = new CellElement();
                   string cellText = footer[column.UniqueName].Text;
                   cell.Data.DataItem = cellText == " " ? "" : cellText;
                   row.Cells.Add(cell);
               }
               e.Worksheet.Table.Rows.Add(row);
           }
       }
     
       protected void Button1_Click(object sender, EventArgs e)
       {
           RadGrid1.MasterTableView.ExportToExcel();
       }

    Thanks,
    Princy
  6. Sambhaji
    Sambhaji avatar
    1 posts
    Member since:
    Sep 2011

    Posted 21 Jan 2015 Link to this post

    Hi All,

    I am exporting telerik Rad grid to excel,but i am showing two Footers.

    Please check the attachment file.
  7. Kostadin
    Admin
    Kostadin avatar
    1708 posts

    Posted 26 Jan 2015 Link to this post

    Hello Sambhaji,

    Could you please let me know whether you are using a ExcelML export format in your case. Also I would appreciate if you can provide your code declaration and the related code behind in order to investigate it further.

    Regards,
    Kostadin
    Telerik
     

    Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

     
  8. Tom
    Tom avatar
    22 posts
    Member since:
    Jan 2011

    Posted 20 Nov 2015 Link to this post

    Was this issue ever solved?  I'm having the same problem.
  9. Kostadin
    Admin
    Kostadin avatar
    1708 posts

    Posted 25 Nov 2015 Link to this post

    Hi,

    Could you please provide a small runnable sample since the issue could not be replicated with the provided code in the Princy's reply?

    Regards,
    Kostadin
    Telerik
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
  10. Tom
    Tom avatar
    22 posts
    Member since:
    Jan 2011

    Posted 25 Nov 2015 in reply to Kostadin Link to this post

    nevermind.  The solutions was to enable viewstate.  Thanks.
Back to Top
UI for ASP.NET Ajax is Ready for VS 2017