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

[Solved] Export Error!!!

14 Answers 374 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Mike
Top achievements
Rank 1
Mike asked on 30 Mar 2009, 08:17 PM
I have a RadGrid which has export buttons above it that I use to export to excel, word, and pdf.  They work fine on all of my other pages.  However, we are experiencing a major issue when I have some code behind writing to a tooltip.

ToolTip components from RadControls
<telerik:GridTemplateColumn HeaderText="Actions" HeaderStyle-Width="50" ItemStyle-HorizontalAlign="center">     
   <ItemTemplate>    
     <telerik:RadToolTip ID="RadToolTipMessage" TargetControlID="LabelRefreshStatus" RelativeTo="Element" Position="BottomLeft" runat="server" />   
     <telerik:RadToolTip ID="RadToolTipImage" TargetControlID="ImageErrorMessage" RelativeTo="Element" Position="BottomLeft" ManualClose="true" runat="server" />   
     <asp:ImageButton ID="ImageButtonDetails" ImageUrl="~/images/office/txt.gif" AlternateText="See Details" runat="server" />    
     <asp:Label ID="LabelRefreshStatus" runat="server" />   
     <telerik:RadToolTip ID="RadToolTipDetails" TargetControlID="ImageButtonDetails" Position="TopLeft" Sticky="true" runat="server" />   
   </ItemTemplate>    
</telerik:GridTemplateColumn>     

Code Behind for ToolTip
refreshStatus.Text = EMAUtilities.BatchStatus(Convert.ToInt32(dataItem["STATUS_ID"].Text));     
RadToolTip message = ((RadToolTip)e.Item.Cells[0].FindControl("RadToolTipMessage"));     
RadToolTip imageMessage = ((RadToolTip)e.Item.Cells[0].FindControl("RadToolTipImage"));     
RadToolTip detail = ((RadToolTip)e.Item.Cells[0].FindControl("RadToolTipDetails"));     
Label refreshStatus = (Label)e.Item.Cells[0].FindControl("LabelRefreshStatus");   
System.Web.UI.WebControls.  
Image imageResults = (System.Web.UI.WebControls.Image)e.Item.Cells[0].FindControl("ImageErrorMessage");  

ERROR OCCURS HERE, ALL OF THE LINES ERROR OUT with the message below.
message.Text = "Good Job!";  
imageMessage.Text = "You have done a good job!";  
imageResults.Visible = true;  
refreshStatus.CssClass = "colorGreen";  
imageResults.ImageUrl = "~/images/Good.gif";  
imageResults.Visible = true


ERROR MESSAGE!!
System.NullReferenceException was unhandled by user code
  Message="Object reference not set to an instance of an object."
  Source="App_Web_kktldl24"
  StackTrace:
       at RefreshStatus.RadGrid1_ItemDataBound(Object sender, GridItemEventArgs e) in c:\TFS\MEC.EMA\Development\Source\EMA.Internal\pricing\refresh\RefreshStatus.aspx.cs:line 191
       at Telerik.Web.UI.RadGrid.OnItemDataBound(GridItemEventArgs e)
       at Telerik.Web.UI.GridItem.SetupItem(Boolean dataBind, Object dataItem, GridColumn[] columns, ControlCollection rows)
       at Telerik.Web.UI.GridItemBuilder.InitializeItem(Int32 dataSourceIndex, String& nextItemHierarchicalIndex, Boolean& itemIsInEditMode)
       at Telerik.Web.UI.GridItemBuilder.CreateItems(GridGroupingContext group)
       at Telerik.Web.UI.GridItemBuilder.CreateGroupSubItems(GridGroupingContext group, GridEnumerableBase enumerable)
       at Telerik.Web.UI.GridItemBuilder.HandleGrouping(GridGroupingContext group, GridEnumerableBase enumerable, Boolean& isGroup, Boolean& isGroupFooter)
       at Telerik.Web.UI.GridItemBuilder.CreateItems(GridGroupingContext group)
       at Telerik.Web.UI.GridItemBuilder.CreateGroupSubItems(GridGroupingContext group, GridEnumerableBase enumerable)
       at Telerik.Web.UI.GridItemBuilder.HandleGrouping(GridGroupingContext group, GridEnumerableBase enumerable, Boolean& isGroup, Boolean& isGroupFooter)
       at Telerik.Web.UI.GridItemBuilder.CreateItems(GridGroupingContext group)
       at Telerik.Web.UI.GridTableView.CreateItems(IEnumerator enumerator, GridColumn[] columns, ControlCollection controls)
       at Telerik.Web.UI.GridTableView.CreateControlHierarchy(Boolean useDataSource)
       at Telerik.Web.UI.GridTableView.CreateChildControls(IEnumerable dataSource, Boolean useDataSource)
       at System.Web.UI.WebControls.CompositeDataBoundControl.PerformDataBinding(IEnumerable data)
       at System.Web.UI.WebControls.DataBoundControl.OnDataSourceViewSelectCallback(IEnumerable data)
       at System.Web.UI.DataSourceView.Select(DataSourceSelectArguments arguments, DataSourceViewSelectCallback callback)
       at System.Web.UI.WebControls.DataBoundControl.PerformSelect()
       at Telerik.Web.UI.GridTableView.PerformSelect()
       at System.Web.UI.WebControls.BaseDataBoundControl.DataBind()
       at Telerik.Web.UI.GridTableView.DataBind()
       at Telerik.Web.UI.RadGrid.DataBind()
       at Telerik.Web.UI.RadGrid.AutoDataBind(GridRebindReason rebindReason)
       at Telerik.Web.UI.RadGrid.RebindForExport()
       at Telerik.Web.UI.Grid.Export.TableViewExporter.PrepareForExport()
       at Telerik.Web.UI.Grid.Export.TableViewExporter.page_PreRender(Object sender, EventArgs e)
       at System.EventHandler.Invoke(Object sender, EventArgs e)
       at System.Web.UI.Control.OnPreRender(EventArgs e)
       at System.Web.UI.Control.PreRenderRecursiveInternal()
       at System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)
  InnerException:



Here is my export code behind from my user control
public partial class controls_exportRadGrid : System.Web.UI.UserControl  
{  
    protected void Page_Load(object sender, EventArgs e)  
    {  
 
    }         
 
    /// <summary> 
    /// Handles the Click event of the ButtonExcel control.  
    /// </summary> 
    /// <param name="sender">The source of the event.</param> 
    /// <param name="e">The <see cref="System.EventArgs"/> instance containing the event data.</param> 
    protected void ButtonExcel_Click(object sender, System.EventArgs e)  
    {  
        ConfigureExport();  
        RadGrid Grid1 = (RadGrid)Page.Master.FindControl("Main").FindControl("RadGrid1");  
        Grid1.MasterTableView.ExportToExcel();  
    }  
 
    /// <summary> 
    /// Handles the Click event of the ButtonWord control.  
    /// </summary> 
    /// <param name="sender">The source of the event.</param> 
    /// <param name="e">The <see cref="System.EventArgs"/> instance containing the event data.</param> 
    protected void ButtonWord_Click(object sender, System.EventArgs e)  
    {  
        ConfigureExport();   
        RadGrid Grid1 = (RadGrid)Page.Master.FindControl("Main").FindControl("RadGrid1");  
        Grid1.MasterTableView.ExportToWord();  
    }  
 
    /// <summary> 
    /// Handles the Click event of the ButtonPDF control.  
    /// </summary> 
    /// <param name="sender">The source of the event.</param> 
    /// <param name="e">The <see cref="System.EventArgs"/> instance containing the event data.</param> 
    protected void ButtonPDF_Click(object sender, System.EventArgs e)  
    {  
        ConfigureExport();  
        RadGrid Grid1 = (RadGrid)Page.Master.FindControl("Main").FindControl("RadGrid1");  
        Grid1.ExportSettings.Pdf.PageHeight = Unit.Parse("200mm");  
        Grid1.ExportSettings.Pdf.PageWidth = Unit.Parse("500mm");  
        Grid1.MasterTableView.Columns.FindByDataField("STATUS_ID").Visible = false;  
        Grid1.MasterTableView.ExportToPdf();  
    }  
 
    /// <summary> 
    /// Handles the Click event of the ButtonCSV control.  
    /// </summary> 
    /// <param name="sender">The source of the event.</param> 
    /// <param name="e">The <see cref="System.EventArgs"/> instance containing the event data.</param> 
    protected void ButtonCSV_Click(object sender, System.EventArgs e)  
    {  
        ConfigureExport(); RadGrid Grid1 = (RadGrid)Page.Master.FindControl("Main").FindControl("RadGrid1");  
        Grid1.MasterTableView.ExportToCSV();  
    }  
 
    /// <summary> 
    /// Configures the export.  
    /// </summary> 
    public void ConfigureExport()  
    {  
        RadGrid Grid1 = (RadGrid)Page.Master.FindControl("Main").FindControl("RadGrid1");  
        Grid1.ExportSettings.ExportOnlyData = true;  
        Grid1.ExportSettings.IgnorePaging = true;  
        Grid1.ExportSettings.OpenInNewWindow = true;  
    }         
}      

Can you provide me with a solution to remove this error and allow me to Export the data?

Thank You!

14 Answers, 1 is accepted

Sort by
0
Sebastian
Telerik team
answered on 02 Apr 2009, 03:50 PM
Hello Mike,

Can you please specify at which stage of the lifecycle the exception is generated (debugging your code)? It seems that some control instance cannot be accessed from within the ItemDataBound handler of the grid and this generates the exception in question.

I will also appreciate if you share with us the implementation of the ItemDataBound handler of the grid where the exception is thrown. This can shed some additional light on the matter and help us determine how to tackle the problem.

Kind regards,
Sebastian
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 02 Apr 2009, 03:59 PM
Is this what you are looking for in addition to the code listed above?
 protected void RadGrid1_ItemDataBound(object sender, GridItemEventArgs e)  
    {  
        if (e.Item is GridDataItem)  
        {  
            GridDataItem dataItem = e.Item as GridDataItem;  
 
    }  
    }  
 
<telerik:RadGrid ID="RadGrid1"   
AllowMultiRowSelection="True"   
AllowSorting="True" 
AllowNaturalSort="True"   
AllowPaging="False" 
AutoGenerateColumns="False"   
AlternatingItemStyle-HorizontalAlign="Center"   
BackColor="#ffffff"   
CellPadding="0"   
CellSpacing="0" 
EnableEmbeddedSkins="False" 
GridLines="None"   
GroupingEnabled="True"   
Height="550px"                            
ItemStyle-Height="20" 
ItemStyle-HorizontalAlign="Center"     
OnSortCommand="RadGrid1_SortCommand"   
OnNeedDataSource="RadGrid1_NeedDataSource"   
OnItemDataBound="RadGrid1_ItemDataBound"   
ShowFooter="True"   
ShowHeader="True"   
ShowGroupPanel="True"   
ShowStatusBar="True"   
Skin="mySkin"    
Width="100%"   
Runat="server">  
 
<MasterTableView AllowMultiColumnSorting="True" DataKeyNames="OFFER_ID,CUSTOMER,PRICE_REQUEST_ID" TableLayout="Fixed" HeaderStyle-Wrap="false" Width="100%">  
                      <Columns> 
...............  
                       </Columns> 
                      <HeaderStyle Width="100px" /> 
                  </MasterTableView> 
                <ClientSettings AllowColumnsReorder="True" AllowDragToGroup="True" ReorderColumnsOnClient="True" AllowRowHide="True">  
                  <Resizing AllowColumnResize="True" AllowRowResize="False" ResizeGridOnColumnResize="True" ClipCellContentOnResize="True" EnableRealTimeResize="True" /> 
                  <Scrolling AllowScroll="True" UseStaticHeaders="True" SaveScrollPosition="True" FrozenColumnsCount="2" />      
                  <Selecting AllowRowSelect="True" /> 
                </ClientSettings> 
             </telerik:RadGrid> 
0
Sebastian
Telerik team
answered on 06 Apr 2009, 03:11 PM
Hello Mike,

Does temporary removing the tooltip instances from the item template of the template column/the relevant code-behind logic eliminates the error you get?

If this does not help, the best means to progress in our investigation is to prepare a stripped working version of your project, exhibiting the problem, and send it enclosed to a formal support ticket. We will test/debug it locally and will get back to you with our findings.

Regards,
Sebastian
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 07 Apr 2009, 08:15 PM
Sebastian,

Yes, removing it got rid of the error.  But, I want to use the tooltip!
0
Rosen
Telerik team
answered on 09 Apr 2009, 08:12 AM
Hello Mike,

Are you accessing the RadToolTip inside the ItemDataBound event? If this is the case you should skip this logic when exporting ( by adding a check for a flag for example) as the RadToolTip will be removed from the output causing the control to be missing from controls collection when access inside ItemDataBound event handler.

Best wishes,
Rosen
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 09 Apr 2009, 12:19 PM
Yes, I am using it in the itemDataBound.  How, do I skip it on an export? Can you please provide an example?
0
Sebastian
Telerik team
answered on 09 Apr 2009, 12:24 PM
Hello Mike,

You can raise a flag when pdf export is triggered and execute the logic for tooltips insertion inside the ItemDataBound event of the grid conditionally based on the value of this flag.  A sample approach that can be used for reference is available in this help topic:

http://www.telerik.com/help/aspnet-ajax/grdexporttipstricks.html (paragraph 'RadGrid formatting and pdf export')

Best regards,
Sebastian
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 09 Apr 2009, 12:31 PM
Sebatian,

That may have fixed one issue, now I am getting the following error which is also in my ItemDataBound for displaying text in the RadToolTip.

 RadToolTip message = ((RadToolTip)e.Item.Cells[0].FindControl("RadToolTipMessage")); 


Line 223:   break;
Line 224:   case ((int)Enumeration.Status.Week):
Line 225: message.Text = "Great Job!";Line 226:   imageMessage.Text = "You have done great this week!";
Line 227:   imageResults.Visible = true;
0
Rosen
Telerik team
answered on 10 Apr 2009, 03:29 PM
Hi Mike,

You should wrap the entire code which use the RadToolTip (message variable) inside the IsExporting block?

Regards,
Rosen
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 10 Apr 2009, 03:31 PM
Example please!
0
Sebastian
Telerik team
answered on 13 Apr 2009, 07:20 AM
Hello Mike,

Here is some pseudo code that can get you started:

protected void RadGrid1_ItemDataBound(object sender, GridItemEventArgs e)     
    {     
        if (!isExporting)     
        {     
              //YOUR RADTOOLTIP CODE GOES HERE!  
        }     
    }     
 


Regards,
Sebastian
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 13 Apr 2009, 07:16 PM
I get the following error!

Description: An error occurred during the compilation of a resource required to service this request. Please review the following specific error details and modify your source code appropriately.

Compiler Error Message: CS0103: The name 'isExporting' does not exist in the current context

Source Error:

Line 259:            }
Line 260:
Line 261: if (!isExporting)
0
Princy
Top achievements
Rank 2
answered on 16 Apr 2009, 05:19 AM
Hello Mike,

Check if you have declared the isExporting variable globally as shown below:
bool isExporting= false
protected void RadGrid1_ItemCommand(object source, GridCommandEventArgs e) 
    {     
    if (e.CommandName == RadGrid.ExportToPdfCommandName)  
       {            
    isExporting= true;     
         
      }   
  }    
 
 protected void RadGrid1_ItemDataBound(object sender, GridItemEventArgs e)  
   {   
     if (isExporting)   
      { 
        //RadToolTip Code 
      } 
   }  
 

You can also go through the section 'RadGrid formatting and PDF export' of the following document :
Exporting tips and tricks

Thanks
Princy.
0
Mike
Top achievements
Rank 1
answered on 16 Apr 2009, 12:38 PM
It exports, but now the ToolTips are empty in the grid? 

I am not using the ItemCommand since my Export button is outside the RadGrid.
Tags
Grid
Asked by
Mike
Top achievements
Rank 1
Answers by
Sebastian
Telerik team
Mike
Top achievements
Rank 1
Rosen
Telerik team
Princy
Top achievements
Rank 2
Share this question
or