how to export radgrid

8 posts, 0 answers
  1. Jack
    Jack avatar
    67 posts
    Member since:
    Jul 2010

    Posted 02 Dec 2010 Link to this post

    i want to export radgrid in excel with column names when column autogenerated property is false and columns are dynamically generated.

    i had use this code

    RadGrid1.MasterTableView.ExportToExcel(); 

    but it export without header text.

    i want to export with header text.
  2. Daniel
    Admin
    Daniel avatar
    4946 posts

    Posted 02 Dec 2010 Link to this post

    Hello Goldy,

    The headers won't be exported properly if your RadGrid is invisible. Can you please confirm whether this is the case? If this is not so, please post some more information about your scenario.

    Best regards,
    Daniel
    the Telerik team
    Browse the vast support resources we have to jumpstart 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.
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Jack
    Jack avatar
    67 posts
    Member since:
    Jul 2010

    Posted 02 Dec 2010 Link to this post

    my radgrid is visible at run time but when i export, it is exporting successfully but the headers are not coming while all the data is coming..

    I am attaching a jpeg file plz see that..


       foreach (DataColumn co in DT.Columns)
                    {
                        GridBoundColumn bb;
                        bb = new GridBoundColumn();
                        bb.HeaderText = DT.Columns[j].Caption;
                      
                        bb.DataField = DT.Columns[j].Caption;
                        if (bb.HeaderText == "ItemId" || bb.HeaderText=="s2")
                        {
                            bb.Visible = false;
                        }
                        
                        j++;
                        RadGrid1.MasterTableView.Columns.Add(bb);
                        this.PlaceHolder1.Controls.Add(RadGrid1);
                        

                    }


       foreach (DataColumn co in DT.Columns)
                    {
                        GridBoundColumn bb;
                        bb = new GridBoundColumn();
                        bb.HeaderText = DT.Columns[j].Caption;
                      
                        bb.DataField = DT.Columns[j].Caption;
                        if (bb.HeaderText == "ItemId" || bb.HeaderText=="s2")
                        {
                            bb.Visible = false;
                        }
                        
                        j++;
                        RadGrid1.MasterTableView.Columns.Add(bb);
                        this.PlaceHolder1.Controls.Add(RadGrid1);
                        

                    }
       foreach (DataColumn co in DT.Columns)
                    {
                        GridBoundColumn bb;
                        bb = new GridBoundColumn();
                        bb.HeaderText = DT.Columns[j].Caption;
                      
                        bb.DataField = DT.Columns[j].Caption;
                        if (bb.HeaderText == "ItemId" || bb.HeaderText=="s2")
                        {
                            bb.Visible = false;
                        }
                        
                        j++;
                        RadGrid1.MasterTableView.Columns.Add(bb);
                        this.PlaceHolder1.Controls.Add(RadGrid1);
                        

                    }
       foreach (DataColumn co in DT.Columns)
                    {
                        GridBoundColumn bb;
                        bb = new GridBoundColumn();
                        bb.HeaderText = DT.Columns[j].Caption;
                      
                        bb.DataField = DT.Columns[j].Caption;
                        if (bb.HeaderText == "ItemId" || bb.HeaderText=="s2")
                        {
                            bb.Visible = false;
                        }
                        
                        j++;
                        RadGrid1.MasterTableView.Columns.Add(bb);
                        this.PlaceHolder1.Controls.Add(RadGrid1);
                        

                    }
       foreach (DataColumn co in DT.Columns)
                    {
                        GridBoundColumn bb;
                        bb = new GridBoundColumn();
                        bb.HeaderText = DT.Columns[j].Caption;
                      
                        bb.DataField = DT.Columns[j].Caption;
                        if (bb.HeaderText == "ItemId" || bb.HeaderText=="s2")
                        {
                            bb.Visible = false;
                        }
                        
                        j++;
                        RadGrid1.MasterTableView.Columns.Add(bb);
                        this.PlaceHolder1.Controls.Add(RadGrid1);
                        

                    }
       foreach (DataColumn co in DT.Columns)
                    {
                        GridBoundColumn bb;
                        bb = new GridBoundColumn();
                        bb.HeaderText = DT.Columns[j].Caption;
                      
                        bb.DataField = DT.Columns[j].Caption;
                        if (bb.HeaderText == "ItemId" || bb.HeaderText=="s2")
                        {
                            bb.Visible = false;
                        }
                        
                        j++;
                        RadGrid1.MasterTableView.Columns.Add(bb);
                        this.PlaceHolder1.Controls.Add(RadGrid1);
                        

                    }
       foreach (DataColumn co in DT.Columns)
                    {
                        GridBoundColumn bb;
                        bb = new GridBoundColumn();
                        bb.HeaderText = DT.Columns[j].Caption;
                      
                        bb.DataField = DT.Columns[j].Caption;
                        if (bb.HeaderText == "ItemId" || bb.HeaderText=="s2")
                        {
                            bb.Visible = false;
                        }
                        
                        j++;
                        RadGrid1.MasterTableView.Columns.Add(bb);
                        this.PlaceHolder1.Controls.Add(RadGrid1);
                        

                    }
       foreach (DataColumn co in DT.Columns)
                    {
                        GridBoundColumn bb;
                        bb = new GridBoundColumn();
                        bb.HeaderText = DT.Columns[j].Caption;
                      
                        bb.DataField = DT.Columns[j].Caption;
                        if (bb.HeaderText == "ItemId" || bb.HeaderText=="s2")
                        {
                            bb.Visible = false;
                        }
                        
                        j++;
                        RadGrid1.MasterTableView.Columns.Add(bb);
                        this.PlaceHolder1.Controls.Add(RadGrid1);
                        

                    }
       foreach (DataColumn co in DT.Columns)
                    {
                        GridBoundColumn bb;
                        bb = new GridBoundColumn();
                        bb.HeaderText = DT.Columns[j].Caption;
                      
                        bb.DataField = DT.Columns[j].Caption;
                        if (bb.HeaderText == "ItemId" || bb.HeaderText=="s2")
                        {
                            bb.Visible = false;
                        }
                        
                        j++;
                        RadGrid1.MasterTableView.Columns.Add(bb);
                        this.PlaceHolder1.Controls.Add(RadGrid1);
                        

                    }
  5. Daniel
    Admin
    Daniel avatar
    4946 posts

    Posted 07 Dec 2010 Link to this post

    Hello Goldy,

    Could you please post your code in this thread? I will try to create a runnable project in order to reproduce the problem on my end.
    Thank you.

    Best regards,
    Daniel
    the Telerik team
    Browse the vast support resources we have to jumpstart 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.
  6. Gaurav
    Gaurav avatar
    6 posts
    Member since:
    Apr 2011

    Posted 12 Apr 2011 Link to this post

    I am facing the same issue, column headers are not getting exported.
    In my case, am making div containing the grid invisible at run time, which is my requirement.

    Is there any way to export column headers too along with the data ??

    Note :- I cannot show the grid on the page as it is specially created for the purpose of export.

    Any kind of help will be highly appreciated.

  7. Daniel
    Admin
    Daniel avatar
    4946 posts

    Posted 14 Apr 2011 Link to this post

    Hello Gaurav,

    Below you can find a simple code-snippet that demonstrates how to export invisible RadGrid. Please try this approach and let me know whether it is suitable for you.
    <asp:Button ID="Button1" runat="server" Text="Export" onclick="Button1_Click" />
    <telerik:RadGrid ID="ExportGrid" runat="server" Visible="false">
        <ExportSettings ExportOnlyData="true" IgnorePaging="false" OpenInNewWindow="true" />
    </telerik:RadGrid>

    protected void Button1_Click(object sender, EventArgs e)
    {
        ExportGrid.Visible = true;
        ExportGrid.DataSource = new string[] { "John", "Michael", "Tina" };
        ExportGrid.DataBind();
        ExportGrid.MasterTableView.ExportToExcel();
    }

    Note that even though I set Visible to true, the control won't be displayed on the page.

    Best 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.

  8. BO
    BO avatar
    2 posts
    Member since:
    Mar 2015

    Posted 19 Jul 2015 in reply to Gaurav Link to this post

    I had the same problem (dynamically created bound columns missing header text on export).  After some tinkering, I found that rebinding the grid just before the export refreshes the grid header definition.
  9. Daniel
    Admin
    Daniel avatar
    4946 posts

    Posted 21 Jul 2015 Link to this post

    Hello Bo,

    RadGrid needs to recreate its structure in such scenario and this is why you need to call Rebind (or DataBind for simple datasource scenario).
    In most cases this happens when you need to show something that has been invisible before - be it columns or the whole control.

    Regards,
    Daniel
    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
Back to Top
UI for ASP.NET Ajax is Ready for VS 2017