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

Rad grid dynamic header is not showing in export to excel

1 Answer 100 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Kishore
Top achievements
Rank 1
Kishore asked on 09 Jul 2014, 11:02 AM
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.

1 Answer, 1 is accepted

Sort by
0
Konstantin Dikov
Telerik team
answered on 14 Jul 2014, 08:14 AM
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.

 
Tags
General Discussions
Asked by
Kishore
Top achievements
Rank 1
Answers by
Konstantin Dikov
Telerik team
Share this question
or