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

Object reference not set to an instance of an object.

3 Answers 319 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Kevin
Top achievements
Rank 1
Kevin asked on 20 Mar 2012, 08:48 PM
ok, this error happens on export to excel from my radgrid.  I got everything working fine in it and then they wanted me to put on a looker service with a pop-up panel.  Since then it breaks, the export to excel, if I take out the code it works fine, i do not want it exported to excel.
it breaks on the follwoing line which is part of the radgri_ItemCreated  
pce.BehaviorID = behaviorID

How can I get around this to export the grid without the control

added peices to grid

<telerik:GridTemplateColumn>
                                             <ItemTemplate>
                                                <asp:Image ID="imgLooker" runat="server" ImageUrl="~/Images/ViewResources.gif" ImageAlign="Middle" BorderStyle="None" />
                                                <asp:PopupControlExtender ID="popInfo" runat="server" PopupControlID="pnlPop" TargetControlID="imgLooker" DynamicContextKey='<% #Eval("intRecId") %>' 
                                                DynamicControlID="pnlpop" DynamicServiceMethod="HelloWorld" Position="bottom"></asp:PopupControlExtender>
                                            </ItemTemplate>
                                        </telerik:GridTemplateColumn>
  
 Protected Sub myRadGrid_ItemCreated(sender As Object, e As Telerik.Web.UI.GridItemEventArgs) Handles myRadGrid.ItemCreated
        If TypeOf e.Item Is GridCommandItem Then
            ScriptManager.GetCurrent(Page).RegisterPostBackControl(e.Item.FindControl("btnExport"))
        End If
  
        If TypeOf e.Item Is GridDataItem Then
            Dim pce As PopupControlExtender = TryCast(e.Item.FindControl("popInfo"), PopupControlExtender)
  
            Dim behaviorID As String = "pce_" + e.Item.RowIndex.ToString
            pce.BehaviorID = behaviorID
  
            Dim img As Image = DirectCast(e.Item.FindControl("imgLooker"), Image)
  
            Dim OnMouseOverScript As String = String.Format("$find('{0}').showPopup();", behaviorID)
            Dim OnMouseOutScript As String = String.Format("$find('{0}').hidePopup();", behaviorID)
  
            img.Attributes.Add("onmouseover", OnMouseOverScript)
            img.Attributes.Add("onmouseout", OnMouseOutScript)
        End If
    End Sub
  
  
  
FUll Grid layout
<telerik:RadGrid ID="myRadGrid" runat="server" Width="98%" BorderWidth="1px" CellPadding="6" GridLines="None" BorderColor="#404040" Skin="Web20" ShowFooter="true">
                            <ExportSettings HideStructureColumns="true" ExportOnlyData="true" IgnorePaging="true" OpenInNewWindow="true" FileName="Inventory"></ExportSettings>
                            <MasterTableView AutoGenerateColumns="false" DataKeyNames="intRecId" Name="MasterGrid" BorderColor="#404040" Font-Size="9" Font-Names="Veranda,arial,sans-serif" HeaderStyle-HorizontalAlign="Center" 
                            GridLines="Both" BorderWidth="1px" CommandItemDisplay="Top" HierarchyLoadMode="ServerBind" AllowPaging="true" PageSize="20" PagerStyle-Mode="NumericPages"><ItemStyle HorizontalAlign="Center"/>
                            <AlternatingItemStyle BackColor="#B0C4DE"  HorizontalAlign="Center" /><HeaderStyle ForeColor="White" Font-Bold="true" BorderColor="#404040" BorderWidth="1px" />
                                <CommandItemTemplate>
                                    <table width="100%">
                                        <tr>
                                            <td align="right"><asp:Button ID="btnExport" runat="server" CommandName="ExportToExcel" Text="Export Excel" /></td>
                                        </tr>
                                    </table>
                                </CommandItemTemplate>
                                <Columns>
                                        <telerik:GridTemplateColumn>
                                             <ItemTemplate>
                                                <asp:Image ID="imgLooker" runat="server" ImageUrl="~/Images/ViewResources.gif" ImageAlign="Middle" BorderStyle="None" />
                                                <asp:PopupControlExtender ID="popInfo" runat="server" PopupControlID="pnlPop" TargetControlID="imgLooker" DynamicContextKey='<% #Eval("intRecId") %>' 
                                                DynamicControlID="pnlpop" DynamicServiceMethod="HelloWorld" Position="bottom"></asp:PopupControlExtender>
                                            </ItemTemplate>
                                        </telerik:GridTemplateColumn>
                                        <telerik:GridEditCommandColumn UniqueName="EditCommandColumn"></telerik:GridEditCommandColumn>
                                        <telerik:GridBoundColumn DataField="strCategory" HeaderText="CATEGORY" />
                                        <telerik:GridBoundColumn DataField="strManufacturer" HeaderText="MANUFACTURER" />
                                        <telerik:GridBoundColumn DataField="strmake" HeaderText="MAKE" />
                                        <telerik:GridBoundColumn DataField="strPoNum" HeaderText="PO #" />
                                        <telerik:GridBoundColumn DataField="strAssetNum" HeaderText="ASSET #" />
                                        <telerik:GridBoundColumn DataField="strSN" HeaderText="SN" />
                                        <telerik:GridBoundColumn DataField="fltCost" HeaderText="COST" />
                                        <telerik:GridBoundColumn DataField="FUND" HeaderText="FUND" />
                                        <telerik:GridBoundColumn DataField="ws" HeaderText="WTY_START" />
                                        <telerik:GridBoundColumn DataField="we" HeaderText="WTY_END" />
                                        <telerik:GridBoundColumn DataField="QTY" HeaderText="QTY" />
                                </Columns>
                                <EditFormSettings EditFormType="Template">
                                    <FormTemplate>
                                        <table width="100%">
                                            <tr>
                                                <td style="height:8px"></td>
                                            </tr>
                                            <tr>
                                                <td><b>EDIT DETAILS</b></td>
                                            </tr>
                                        </table>
                                        <table width="100%">
                                            <tr>
                                                <td style="width:50%" align="right">Enter PO </td>
                                                <td style="width:50%" align="left">
                                                    <asp:TextBox ID="txtPoNum" runat="server" Width="160px" Text='<%# Bind("strPoNum") %>'></asp:TextBox>
                                                </td>
                                            </tr>
                                            <tr>
                                                <td style="height:5px"></td>
                                            </tr>
                                            <tr>
                                                <td style="width:50%" align="right">Enter AssetTag </td>
                                                <td style="width:50%" align="left">
                                                    <asp:TextBox ID="txtAssetNum" runat="server" Width="160px" Text='<%# Bind("strAssetNum") %>'></asp:TextBox>
                                                </td>
                                            </tr>
                                                <tr>
                                                <td style="height:5px"></td>
                                            </tr>
                                            <tr>
                                                <td style="width:50%" align="right">Enter SN </td>
                                                <td style="width:50%" align="left">
                                                    <asp:TextBox ID="txtSn" runat="server" Width="160px" Text='<%# Bind("strSN") %>'></asp:TextBox>
                                                </td>
                                            </tr>
                                            <tr>
                                                <td style="height:5px"></td>
                                            </tr>
                                            <tr>
                                                <td style="width:50%" align="right">Enter Cost </td>
                                                <td style="width:50%" align="left">
                                                    <asp:TextBox ID="txtCost" runat="server" Width="160px" Text='<%# Bind("fltCost") %>'></asp:TextBox>
                                                    <asp:FilteredTextBoxExtender ID="txtCost_FTE" runat="server" Enabled="True" TargetControlID="txtCost" ValidChars="." FilterType="Custom, Numbers" />
                                                </td>
                                            </tr>
                                            <tr>
                                                <td style="height:5px"></td>
                                            </tr>
                                            <tr>
                                                <td style="width:50%" align="right">Warranty Start </td>
                                                <td style="width:50%" align="left">
                                                    <asp:TextBox ID="txtWStart" runat="server" style="cursor:pointer; margin-right: 0px;"  Width="160px" Text='<%# Bind("ws") %>'></asp:TextBox>
                                                    <asp:CalendarExtender ID="txtWStart_CE" runat="server" Enabled="True" TargetControlID="txtWStart"></asp:CalendarExtender>
                                                </td>
                                            </tr>
                                                <tr>
                                                <td style="height:5px"></td>
                                            </tr>
                                            <tr>
                                                <td style="width:50%" align="right">Warranty End </td>
                                                <td style="width:50%" align="left">
                                                    <asp:TextBox ID="txtWEnd" runat="server" style="cursor:pointer; margin-right: 0px;"  Width="160px" Text='<%# Bind("we") %>'></asp:TextBox>
                                                    <asp:CalendarExtender ID="txtWEnd_CE" runat="server" Enabled="True" TargetControlID="txtWEnd"></asp:CalendarExtender>
                                                </td>
                                            </tr>
                                        </table>
                                        <table width="100%">
                                            <tr>
                                                <td>
                                                    <asp:LinkButton ID="lnkSubmit" runat="server" text='<%# IIf((TypeOf(Container) is GridEditFormInsertItem), "Insert", "Update") %>' 
                                                    CommandName='<%# IIf((TypeOf(Container) is GridEditFormInsertItem), "PerformInsert", "Update")%>'></asp:LinkButton>
                                                          
                                                    <asp:LinkButton ID="lnkCancel" runat="server" CausesValidation="false" CommandName="Cancel" Text="Cancel"></asp:LinkButton>
                                                </td>
                                            </tr>
                                            <tr>
                                                <td style="height:8px"></td>
                                            </tr>
                                        </table>
                                    </FormTemplate>
                                </EditFormSettings>
                            </MasterTableView>
                            </telerik:RadGrid>

3 Answers, 1 is accepted

Sort by
0
Accepted
Daniel
Telerik team
answered on 23 Mar 2012, 11:00 AM
Hi Kevin,

Try this way:
Dim IsExport As Boolean = False
 
Protected Sub myRadGrid_ItemCommand(ByVal sender As Object, ByVal e As Telerik.Web.UI.GridCommandEventArgs) Handles myRadGrid.ItemCommand
    If e.CommandName = "ExportToExcel" Then
        IsExport = True
    End If
End Sub

    Protected Sub myRadGrid_ItemCreated(ByVal sender As Object, ByVal e As Telerik.Web.UI.GridItemEventArgs) Handles myRadGrid.ItemCreated
        If Not IsExport Then
            'PUT YOUR CODE HERE
        End If
End Sub

Regards,
Daniel
the Telerik team
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to their blog feed now.
0
Kevin
Top achievements
Rank 1
answered on 23 Mar 2012, 03:23 PM
Sweet, that worked but here is the next thing, before it would eliminate the edit column and now the export leaves it there with my looker column, how can I hide them on export.
0
Kevin
Top achievements
Rank 1
answered on 23 Mar 2012, 03:29 PM
Hi,
never mind I got it, this is under the myRadGrid_ItemCommand, if this is not correct le me know and I will change it.  But it seems to work fine.


  If e.CommandName = "ExportToExcel" Then
            IsExport = True
            myRadGrid.Columns(0).Visible = False
            myRadGrid.Columns(1).Visible = False
        End If
Tags
Grid
Asked by
Kevin
Top achievements
Rank 1
Answers by
Daniel
Telerik team
Kevin
Top achievements
Rank 1
Share this question
or