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

Export To Excel From Rad Grid

1 Answer 145 Views
Grid
This is a migrated thread and some comments may be shown as answers.
kks
Top achievements
Rank 1
kks asked on 01 May 2010, 09:46 AM
Hi Telerik,
While Exporting to Excel, i am getting error like

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.

I am using the VB Code as bellow
    

 

If (Not RadGrid1.MasterTableView.Items.Count = 0) Then   
With RadGrid1   
 .ExportSettings.IgnorePaging = True   
 .ExportSettings.ExportOnlyData = True   
 .ExportSettings.FileName = "ExportedResult"   
 .MasterTableView.ExportToExcel()  
End With   
End If 
 
 


if i'll remove the line " ExportSettings.IgnorePaging = True" , it will work. but i need all the pages to be exported.

in aspx, i am used the code like bellow
 

                        <telerik:RadGrid ID="RadGrid1" runat="server" AllowPaging="True" AutoGenerateColumns="true"   
                            DataSourceID="sqlData1" EnableEmbeddedSkins="False" GridLines="None"   
                            EnableAJAX="True" > 
                            <HeaderContextMenu EnableTheming="True">  
                                <CollapseAnimation Type="OutQuint" Duration="200"></CollapseAnimation> 
                            </HeaderContextMenu> 
                            <MasterTableView DataSourceID="sqlData1" AllowFilteringByColumn="false" PageSize="50">  
                                <RowIndicatorColumn> 
                                    <HeaderStyle Width="20px"></HeaderStyle> 
                                </RowIndicatorColumn> 
                                <ExpandCollapseColumn> 
                                    <HeaderStyle Width="20px"></HeaderStyle> 
                                </ExpandCollapseColumn> 
                                <Columns> 
                                </Columns> 
                            </MasterTableView> 
                            <FilterMenu EnableTheming="True">  
                                <CollapseAnimation Type="OutQuint" Duration="200"></CollapseAnimation> 
                            </FilterMenu> 
                        </telerik:RadGrid> 
                        <asp:SqlDataSource ID="sqlData1" runat="server" ConnectionString="<%$ ConnectionStrings:PAMMSConnectionString %>">  
                        </asp:SqlDataSource> 

 

 

 

 

 

 

My grid is creating Dynamically, thats why i used " AutoGenerateColumns="true" ". According to the query user gives , the grid will populate the data.

can you please help me out for this issue.

 

 

 

1 Answer, 1 is accepted

Sort by
0
Daniel
Telerik team
answered on 05 May 2010, 04:34 PM
Hello,

Most probably this is a databinding issue. Please put this button on your page and let me know what happens when you press it:
<asp:Button ID="Button1" runat="server" Text="Click Here" />

Protected Sub Button_Click(sender As Object, e As EventArgs) Handles Button1.Click
    RadGrid1.Rebind()
End Sub

If you RadGrid become a thin line then you should consider using advanced data-binding.

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.
Tags
Grid
Asked by
kks
Top achievements
Rank 1
Answers by
Daniel
Telerik team
Share this question
or