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

[Solved] RadGrid ExportToExcel functionality conflicts with the itemDataBound event

1 Answer 127 Views
Grid
This is a migrated thread and some comments may be shown as answers.
loai taha
Top achievements
Rank 1
loai taha asked on 11 May 2009, 07:44 PM
Hi there,

I'm facing this problem with my Telerik RadGrid control for Asp.Net Ajax (2007.3.1425.20). it keeps giving the "Object reference not set to an instance of an object" error each time I try to export RadGrid data to excel.

The RadGrid contains a template item that is populated using the code below along with the line where the above mentioned error take a place:
Protected Sub myRadGrid_ItemDataBound(ByVal sender As ObjectByVal e As Telerik.Web.UI.GridItemEventArgs) Handles myRadGrid.ItemDataBound  
  
        If e.Item.ItemType = GridItemType.Item Or e.Item.ItemType = GridItemType.AlternatingItem Then  
            Dim xLabel As New Label  
            xLabel = CType(e.Item.FindControl("employedLabel"), Label)  
  
            If xLabel.Text = "False" Then ' here where the error happens 
                xLabel.Text = "No"  
            Else  
                xLabel.Text = "Yes"  
            End If              
        End If  
  
End Sub  

below code is where i rebind the data grid and execute the ExportToExcel function, when I do that the previous mentioned error happens, If I remove the ItemDataBound event it works fine

Protected Sub generateReportButton_Click(ByVal sender As ObjectByVal e As System.Web.UI.ImageClickEventArgs) Handles generateReportButton.Click 
 
        Dim SelectStr As String = "select....." 
 
        'Custome code to manipulate SQL queries 
 
        Me.mySqlDataSource.SelectCommand = SelectStr 
        Me.myRadGrid.Rebind() 
 
        myRadGrid.ExportSettings.OpenInNewWindow = True 
        Me.myRadGrid.MasterTableView.ExportToExcel() 
 
    End Sub 

Would really appreciate if any body can help me with this issue

Thanks in advance :-)

1 Answer, 1 is accepted

Sort by
0
Georgi Krustev
Telerik team
answered on 14 May 2009, 11:54 AM
Hello,

I will suggest you review this online help article devoted on this matter.

Best regards,
Georgi Krustev
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Check out the tips for optimizing your support resource searches.
Tags
Grid
Asked by
loai taha
Top achievements
Rank 1
Answers by
Georgi Krustev
Telerik team
Share this question
or