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

Can't export to Excel...

2 Answers 103 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Ramy Mahrous
Top achievements
Rank 1
Ramy Mahrous asked on 05 Dec 2010, 01:38 PM
protected void RadGrid1_ItemDataBound(object sender, GridItemEventArgs e)
{
if (e.Item is GridDataItem)
{
GridDataItem dataItem = (GridDataItem)e.Item;
rev1Sum += CorrectlyParseString((dataItem["Rev1"].FindControl("Rev1Label") as Label).Text.ToString());
}
else if (e.Item is GridFooterItem)
GridFooterItem footer = (GridFooterItem)e.Item;
(footer["Rev1"].FindControl("Rev1Total") as RadNumericTextBox).Value = Double.Parse(rev1Sum.ToString());
}
}
when I'm exporting to Excel, it gives me Object reference not set to an instance of an object
Rev1 is GridTemplateColumn

2 Answers, 1 is accepted

Sort by
0
Accepted
Daniel
Telerik team
answered on 08 Dec 2010, 01:32 PM
Hello Ramy,

You have to check whether the FindControl method has found the control or it has been removed when exporting. Sample code:
protected void RadGrid1_ItemDataBound(object sender, GridItemEventArgs e)
{
    if (e.Item is GridDataItem)
    {
        GridDataItem dataItem = (GridDataItem)e.Item;
        Label lblRev1 = dataItem["Rev1"].FindControl("Rev1Label") as Label;
        if(lblRev1 != null)
            rev1Sum += CorrectlyParseString(lblRev1.Text);
    }
    else if (e.Item is GridFooterItem)
    {
        GridFooterItem footer = (GridFooterItem)e.Item;
        RadNumericTextBox rntbRev1 = footer["Rev1"].FindControl("Rev1Total") as RadNumericTextBox;
        if(rntbRev1 != null)
            rntbRev1.Value = Double.Parse(rev1Sum.ToString());
    }
}

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.
0
Ramy Mahrous
Top achievements
Rank 1
answered on 08 Dec 2010, 03:20 PM
Thank you, Daniel so much for your help (Y)
Tags
Grid
Asked by
Ramy Mahrous
Top achievements
Rank 1
Answers by
Daniel
Telerik team
Ramy Mahrous
Top achievements
Rank 1
Share this question
or