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

Export ERROR!

3 Answers 73 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Mike
Top achievements
Rank 1
Mike asked on 02 Dec 2008, 09:35 PM
In the RadGrid_itemDataBound event I add an image and CssClass to a column depending on the dataItem returned.   

However, when I export to Excel, Word, or PDF it throws an error (listed below). 

How can I show an image and css in my grid and allow it to export without blowing up on the image or cssClass?

Grid Code Behind in ItemDataBound
message.Text = Convert.ToString(dataItem["ERROR_MESSAGE"].Text);  
imageMessage.Text = Convert.ToString(dataItem["ERROR_MESSAGE"].Text);  
imageResults.Visible = true;  
message.ManualClose = true;  
refreshStatus.CssClass = "colorRed";  
imageResults.ImageUrl = "~/images/ResultError.gif"

Export Code
protected void ButtonExcel_Click(object sender, System.EventArgs e)  
    {  
        ConfigureExport();  
        RadGrid Grid1 = (RadGrid)Page.Master.FindControl("Main").FindControl("RadGrid1");  
        Grid1.MasterTableView.ExportToExcel();  
    }  
public void ConfigureExport()  
    {  
        RadGrid Grid1 = (RadGrid)Page.Master.FindControl("Main").FindControl("RadGrid1");  
        Grid1.ExportSettings.ExportOnlyData = true;  
        Grid1.ExportSettings.IgnorePaging = true;  
        Grid1.ExportSettings.OpenInNewWindow = true;  
    }        


Error!!!

Object reference not set to an instance of an object.

Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.NullReferenceException: Object reference not set to an instance of an object.

Source Error:

Line 134:                    if (!IsPostBack)
Line 135:                    message.Text = Convert.ToString(dataItem["ERROR_MESSAGE"].Text);
Line 136: imageMessage.Text = Convert.ToString(dataItem["ERROR_MESSAGE"].Text);Line 137:                    imageResults.Visible = true;
Line 138:                    message.ManualClose = true;

3 Answers, 1 is accepted

Sort by
0
Daniel
Telerik team
answered on 03 Dec 2008, 08:51 AM
Hello Mike,

I suggest you put a breakpoint on the following line:
imageMessage.Text = Convert.ToString(dataItem["ERROR_MESSAGE"].Text); 

Check whether the imageMessage and dataItem does exist on this point. It would be helpful if you share the code depicted in the error message and provide the full stack trace.

Let us know whether this helps.

Best regards,
Daniel
the Telerik team

Check out Telerik Trainer, the state of the art learning tool for Telerik products.
0
Mike
Top achievements
Rank 1
answered on 03 Dec 2008, 01:16 PM
I did put in the breakpoint and the dataitem does exists.  I think it is more of a problem that the parser or exporter does not know what to do with the tags.
0
johnv
Top achievements
Rank 2
answered on 05 Feb 2009, 10:57 PM
I realize this thread is sort of stale, but I have seen something similar to this before with one of my co-workers. I am not sure this will help but it did the trick with my friend. Try placing in the following code at the very top of your item data bound event:
if (e.Item.ItemType != ListItemType.AlternatingItem && e.Item.ItemType != ListItemType.Item) { return; } 

Since the Item Data Bound event does not have any data in the header, footer, pager, separator, or the like, you may just be falling into that old "I have no data so my data object is null" trap.

I hope this helps,

John
Tags
Grid
Asked by
Mike
Top achievements
Rank 1
Answers by
Daniel
Telerik team
Mike
Top achievements
Rank 1
johnv
Top achievements
Rank 2
Share this question
or