Rad grid dynamic header is not showing in export to excel

2 posts, 0 answers
  1. Kishore
    Kishore avatar
    7 posts
    Member since:
    Apr 2014

    Posted 09 Jul 2014 Link to this post

    I created radgid header name dynamically in ItemDataBound but when i export the data in to excel i am getting the default value from query.

     protected void radweeklygrid_ItemDataBound(object sender, GridItemEventArgs e)
        {
            try
            {
                if (e.Item is GridHeaderItem)
                {
                    GridHeaderItem head = e.Item as GridHeaderItem;
                    if (e.Item.Cells[6].Text == "W1")
                    {
                        e.Item.Cells[6].Text = beforemonday5h.ToString() + "<br/>" + "To" + "<br/>" + beforesunday5h.ToString();
                    }
                    if (e.Item.Cells[7].Text == "W2")
                    {
                        e.Item.Cells[7].Text = beforemonday4h.ToString() + "<br/>" + "To" + "<br/>" + beforesunday4h.ToString();
                    }
                    if (e.Item.Cells[8].Text == "W3")
                    {
                        e.Item.Cells[8].Text = beforemonday3h.ToString() + "<br/>" + "To" + "<br/>" + beforesunday3h.ToString();
                    }
                    if (e.Item.Cells[9].Text == "W4")
                    {
                        e.Item.Cells[9].Text = beforemonday2h.ToString() + "<br/>" + "To" + "<br/>" + beforesunday2h.ToString();
                    }
                    if (e.Item.Cells[10].Text == "W5")
                    {
                        e.Item.Cells[10].Text = beforemonday1h.ToString() + "<br/>" + "To" + "<br/>" + beforesunday1h.ToString();
                    }
                    if (e.Item.Cells[11].Text == "W6")
                    {
                        e.Item.Cells[11].Text = beforemondayh.ToString() + "<br/>" + "To" + "<br/>" + beforesundayh.ToString();
                    }
              }
           }
    }

    and my excel sheet is and i am not able to show the footer also.

    Project Name    Project Manager   Lead Developer   Lead QA       W1     W2     W3    W4    W5      W6     Total hours
       xxxxx                    xxxxx                     xxx                   xxx              40      24       24      9       0         0            97
       xxxxx                    xxxxx                     xxx                   xxx              0        0          6       196   233     45          480

    i want the dynamic value of W1 to W6 in the excel sheet  and footer also not showing.
    In the application interface it was showing the dynamic values of the column and footer value.

  2. Konstantin Dikov
    Admin
    Konstantin Dikov avatar
    1798 posts

    Posted 14 Jul 2014 Link to this post

    Hello Kishore,

    The behavior that you are observing is rather expected and is due to the fact that when you initiate the export, the ItemDataBound event will not fire and you will not change the header text.

    In order to force the ItemDataBound event to fire on export you could handle the server-side OnItemCommand event of the grid and if the command name equals to RadGrid.ExportToExcelCommandName you could call the Rebind() method:
    protected void radweeklygrid_ItemCommand(object sender, GridCommandEventArgs e)
    {
        if (e.CommandName == RadGrid.ExportToExcelCommandName)
        {
            RadGrid1.Rebind();
        }
    }

    As for the footer issue, I am not able to replicate such scenario where the footer is not exported, so please provide a sample that replicates the issue, so we could investigate it locally.


    Regards,
    Konstantin Dikov
    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.

     
Back to Top