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

ExportOnlyData="true" causes null reference exception

2 Answers 50 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Brent
Top achievements
Rank 1
Brent asked on 20 May 2010, 01:51 PM
I am encountering a null reference exception when I set ExportOnlyData="true" and try to export to any format.  If I set ExportOnlyData="false", everything works fine.

Here are the exception details:
[NullReferenceException: Object reference not set to an instance of an object.]
   Telerik.Web.UI.RadAjaxControl.OnPagePreRenderComplete(Object sender, EventArgs e) +116
   System.EventHandler.Invoke(Object sender, EventArgs e) +0
   System.Web.UI.Page.OnPreRenderComplete(EventArgs e) +11039453
   System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +3671

Here is my markup:
<telerik:RadGrid ID="grdResults" Visible="true" runat="server" Skin="WebBlue" AutoGenerateColumns="false" 
    PageSize="20" AllowPaging="true" AllowSorting="true" OnItemCommand="grdResults_ItemCommand" 
    OnNeedDataSource="grdResults_NeedDataSource"
    <ExportSettings FileName="EmployeeSearchResults" ExportOnlyData="true"
    </ExportSettings> 
    <PagerStyle Mode="NumericPages" HorizontalAlign="Center" VerticalAlign="Top" AlwaysVisible="true" 
        Position="Bottom"></PagerStyle> 
    <MasterTableView DataKeyNames="UserId" CommandItemDisplay="Top"
    <CommandItemSettings ShowAddNewRecordButton="false" ShowRefreshButton="false"  ShowExportToCsvButton="true" ShowExportToExcelButton="true" ShowExportToPdfButton="true" ShowExportToWordButton="true" /> 
        <Columns> 
            <telerik:GridTemplateColumn> 
                <ItemTemplate> 
                    <telerik:RadAjaxPanel runat="server"
                        <asp:CheckBox ID="chk" runat="server" Checked='<%# Eval("Selected") %>' AutoPostBack="true" OnCheckedChanged="chk_CheckedChanged" /> 
                        <asp:HiddenField ID="hdn" runat="server" Value=<%# Eval("UserId") %> /> 
                    </telerik:RadAjaxPanel> 
                </ItemTemplate> 
            </telerik:GridTemplateColumn> 
            <telerik:GridBoundColumn SortExpression="EmployeeId" DataField="EmployeeId" HeaderText="Employee ID"
            </telerik:GridBoundColumn> 
            <telerik:GridButtonColumn ButtonType="LinkButton" DataTextField="UserName" HeaderText="Name" 
                SortExpression="UserName" CommandName="UserProfile"
            </telerik:GridButtonColumn> 
            <telerik:GridBoundColumn SortExpression="Title" DataField="Title" HeaderText="Title"
            </telerik:GridBoundColumn> 
            <telerik:GridBoundColumn SortExpression="CompanyName" DataField="CompanyName" HeaderText="Org / Org Unit"
            </telerik:GridBoundColumn> 
            <telerik:GridBoundColumn SortExpression="ManagerName" DataField="ManagerName" HeaderText="Manager"
            </telerik:GridBoundColumn> 
            <telerik:GridBoundColumn SortExpression="EmailAddress" DataField="EmailAddress" HeaderText="Email Address"
            </telerik:GridBoundColumn> 
        </Columns> 
    </MasterTableView> 
</telerik:RadGrid> 


I am using advanced databinding for my datasource, but I have noticed that the NeedsDataSource event never fires when I try to export only data:

        protected void grdResults_NeedDataSource(object sender, Telerik.Web.UI.GridNeedDataSourceEventArgs e) 
        { 
            EmployeeSearchCriteriaDTO criteria = SessionManager.SM.EmployeeSearchCriteria; 
 
            if (criteria != null
            { 
                IList<EmployeeSearchResultDTO> temp = EmployeeSearchManager.Query2(criteria); 
 
                if (SessionManager.SM.ComparisonUserIDs != null
                { 
                    foreach (int id in SessionManager.SM.ComparisonUserIDs) 
                    { 
                        EmployeeSearchResultDTO user = temp.FirstOrDefault(r => r.UserId == id); 
                        if (user != null
                            user.Selected = true
                    } 
                } 
                grdResults.DataSource = temp; 
            } 
        } 

Any ideas?












2 Answers, 1 is accepted

Sort by
0
Daniel
Telerik team
answered on 26 May 2010, 11:04 AM
Hello Brent,

Please try to set RestoreOriginalRenderDelegate to false.
<telerik:RadAjaxPanel ID="RadAjaxPanel1" RestoreOriginalRenderDelegate="false" runat="server">
    <asp:CheckBox ID="chk" runat="server" Checked='<%# Eval("Selected") %>' AutoPostBack="true" />
    <asp:HiddenField ID="hdn" runat="server" Value='<%# Eval("UserId") %>' />
</telerik:RadAjaxPanel>

Regards,
Daniel
the Telerik team

Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
0
Brent
Top achievements
Rank 1
answered on 26 May 2010, 12:07 PM
That was it!  Thanks so much!
Tags
Grid
Asked by
Brent
Top achievements
Rank 1
Answers by
Daniel
Telerik team
Brent
Top achievements
Rank 1
Share this question
or