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

GridTemplateColumn causing "Object reference not set to an instance of an object"

4 Answers 200 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Brad
Top achievements
Rank 1
Brad asked on 27 Dec 2013, 12:22 AM
Hello,

I've been searching for a solution to my problem, but it appears that my issue is unique.

I have had a working web site using RadGrid grid controls for several years until yesterday.  Orginally, this was developed in a 2008 version of Telerik Radcontrols, but I have recently updated it to Version=2013.3.1015.35 to run on a soon-to-be sunset-ed web server.  This upgrade occurred in October or so and things have been fine until a few days ago.

I had to make a change some C# logic that had been discovered to be wrong.  Once the code was tested and approved, the changes were pushed to the production server.  A few days later, it was discovered that there was a problem adding records to the back-end database and having the grid redraw itself.  In fact, the error seems to be coming from the client since it is bypassing any server side error handling that I've built.

The funny twist on this is that there is nothing really happening to the grid.  The users are selecting data from ASP controls that will then be posted back to the database and the grid will be redrawn after the users is done selecting and typing what they need.  They don't get that far.  Before there can be any finalization, the ASP form throws and unhandled exception and references a GridTemplateColumn as the culprit.(See attached).  All server-side code executes without a hitch, but as soon as the grid is being drawn, this error comes up.

Here is the RadGrid ASP.NET code for the GridTemplateColumn:
<telerik:GridTemplateColumn
                                UniqueName="tempLDTEff1"
                                DataType="System.DateTime"
                                HeaderText="LDT1 Effective Date"
                                Reorderable="False"
                                Resizable="False"
                                ShowSortIcon="False"
                                HeaderStyle-Width="80px"
                                DataField="LDT1EffPct"
                                ReadOnly="True"
                                >
                               <HeaderTemplate>
                                
                                    <asp:Label
                                        ID="headLDTEff1" 
                                        Text ="LDT1 Effective Date"
                                        runat="server">
                                    </asp:Label><br />
                                      
                                <asp:TextBox
                                    ID="txtNewLDTDate1"
                                    runat="server"
                                    ToolTip="Type new date to add an LDT.  Can accept 'mm/dd/yyyy' and 'm/d/yyyy' formats"
                                    OnTextChanged="txtNewLDTDate1_OnTextChanged"
                                    AutoPostBack="true"
                                    Font-Bold="true"
                                    onKeyDown="if(event.keyCode==13) event.keyCode=9;"
                                    Width="75px"
                                   >
                                 </asp:TextBox>
                                 <asp:Button
                                    ID ="btnLDT1Delete"
                                    runat="server"
                                    Text ="Delete LDT1"
                                    Visible="false"
                                    OnClick="btnLDT1Delete_Click"
                                    BorderStyle="None"
                                    Font-Underline="true"
                                    ForeColor="Blue"
                                    BackColor="Transparent"/>
                                <asp:RegularExpressionValidator
                                    ID="regExtNewLDTDate1"
                                    runat="server"
                                    ErrorMessage="Invalid date format.  Can accept 'mm/dd/yyyy' and 'm/d/yyyy' formats"
                                    ControlToValidate="txtNewLDTDate1"
                                    Display="Static"
                                    ValidationExpression="^[0,1]?\d{1}\/(([0-2]?\d{1})|([3][0,1]{1}))\/(([1]{1}[9]{1}[9]{1}\d{1})|([2-9]{1}\d{3}))$">
                                </asp:RegularExpressionValidator>
                                <asp:Label
                                    ID="lblLDT1"
                                    runat="server">New LDT Effort %
                                </asp:Label>
                                </HeaderTemplate>
                                <ItemTemplate>                   
                                 <telerik:RadNumericTextBox
                                    runat="server"
                                    ID="txtLDT1Dt"
                                    DbValue='<%# Eval("LDT1EffPct") %>'
                                    OnTextChanged="TextChanged"
                                    AutoPostBack="true"
                                    onKeyDown="if(event.keyCode==13) event.keyCode=9;"
                                    Width="50px">
                                 </telerik:RadNumericTextBox>
                                 </ItemTemplate>
                                <FooterTemplate>
                                    <asp:Label ID="footLDTEff1" Text ="LDT1 Sum" runat="server" Font-Bold="true"></asp:Label>
                                </FooterTemplate>
                                <HeaderStyle Width="80px"></HeaderStyle>
                        </telerik:GridTemplateColumn>
 I am not sure why this is happening and I am out of ideas.  Any help would be greatly appreciated.

4 Answers, 1 is accepted

Sort by
0
Kostadin
Telerik team
answered on 02 Jan 2014, 08:44 AM
Hello Brad,

I prepared a small sample based on the information which you have provided, but I am afraid I was not able to replicate the issue locally. Could you please give the sample a try and let me know how it differs from your real setup? I would appreciate if you could modify the sample and attached it to this thread or let me know how to modify it in order to observe the issue locally.

Regards,
Kostadin
Telerik
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 the blog feed now.
0
Brad
Top achievements
Rank 1
answered on 20 May 2014, 10:35 PM
Hi Kostadin,

I have not been able to resolve this issue.  I can not find anything that is different from you version of the radgrid control than mine.  I am not doing a lot of javascript for the controls and am mostly handling the data changes in post-backs.

What I can tell you for sure is that I did not get back to you on this in December 2013 because I had upgraded to a new version of the controls, which seemed to remedy the situation.  However, I have recently been migrating this application to a new server and took the opportunity to upgrade the Telerik controls again.  In December, I had been working on a trial version (2009.1.0402.35).  For various reasons, the upgrade was not done on one of my applications (the one that is currently having the problem), but another was ubgrated to product version 2013.3.1015.35 and did not experience the same issues as I am now experiencing.  

Now, when I try to upgradet his partiuclar application, this issue comes up again.  I have tried to keep the.NET version 3.5 and also upgraded it to 4.0, but the issue is the same either way.

The upgrade wizard does not seem to handle the upgrade very well.  There are still many manual changes that need to be made to reference the right assemblies.  Everything seems fine until I try to execute post-backs on non-Telerik controls, so it appears that the RadGrid is having issues loading that one column after the orignial loading of the control.

If you have any suggestions, they would be greatly appreciated.
0
Brad
Top achievements
Rank 1
answered on 20 May 2014, 10:42 PM
Here is the code in the .aspx with the ScriptManager and RadGrid code:

<telerik:RadScriptManager ID="RadScriptManager1" Runat="server">
    </telerik:RadScriptManager>

<telerik:RadGrid 
        ID="RadGrid1" 
        runat="server" 
        GridLines="Both"
        CellPadding="1"
        BorderStyle="Solid"
        Skin="Vista"
        AllowAutomaticDeletes="True"
        AllowAutomaticInserts="True"
        AllowAutomaticUpdates="True" 
        AutoGenerateColumns="False" 
        onneeddatasource="RadGrid1_NeedDataSource" 
        onitemdatabound="RadGrid1_ItemDataBound"
        >
    <MasterTableView
        CommandItemDisplay="top"
        EditMode="InPlace"
        ShowFooter="True"
    >
            <%--'<%# !RadGrid1.MasterTableView.IsItemInserted %>'--%>
    <RowIndicatorColumn>
        <HeaderStyle Width="20px"></HeaderStyle>
    </RowIndicatorColumn>

    <ExpandCollapseColumn>
        <HeaderStyle Width="20px"></HeaderStyle>
    </ExpandCollapseColumn>
    <CommandItemTemplate>
                 <asp:LinkButton 
                    ID="lnkAdd"
                    Text="Add new Activity" 
                    CommandName="" 
                    Runat="server"
                    OnClick="AddNewLDTRecord"
                     Visible="true"
                     Font-Size="Medium"
                     Font-Bold="true">
                                <img 
                                    style="border:0px;vertical-align:middle;" 
                                    alt="" 
                                    src="http://demos.telerik.com/aspnet-ajax/grid/examples/programming/commanditem/Images/AddRecord.gif" />
                    Add New Activity</asp:LinkButton>
                  <%--<asp:LinkButton ID="btnCancel" runat="server" CommandName="CancelAll" 
                            Visible='<%# RadGrid1.EditIndexes.Count > 0 || RadGrid1.MasterTableView.IsItemInserted %>'><img style="border:0px;vertical-align:middle;" alt="" src="http://demos.telerik.com/aspnet-ajax/grid/examples/programming/commanditem/Images/Cancel.gif" />Cancel editing</asp:LinkButton>&nbsp;&nbsp;--%>

            </CommandItemTemplate>
     <Columns>
               
                 <telerik:GridBoundColumn 
                    DataField="LDTID" 
                    HeaderText="LDTID" 
                    UniqueName="LDTID" 
                    DataType="System.Int32" 
                    SortExpression="LDTID"
                    ReadOnly="true" Visible="False">
                </telerik:GridBoundColumn>
                <telerik:GridBoundColumn 
                    DataField="EmpID" 
                    HeaderText="EmpID" 
                    UniqueName="EmpID" 
                    DataType="System.Int32" 
                    SortExpression="EmpID"
                     ReadOnly="true" Visible="False">
                </telerik:GridBoundColumn>
                <telerik:GridBoundColumn 
                    DataField="EffDate" 
                    HeaderText="EffDate" 
                    UniqueName="EffDate" 
                    DataType="System.DateTime" 
                    SortExpression="EffDate" 
                    Visible="False"
                    ReadOnly="false"
                     >
                </telerik:GridBoundColumn>
                <telerik:GridCheckBoxColumn 
                    DataField="Submitted" 
                    DataType="System.Boolean" 
                    HeaderText="Submitted" 
                    SortExpression="Submitted" 
                    UniqueName="Submitted"
                    ReadOnly="true" 
                    Visible="False">
                </telerik:GridCheckBoxColumn>
               <telerik:GridBoundColumn 
                    HeaderText="EffID" 
                    UniqueName="EffID"
                    DataField="EffID" 
                    DataType="System.Int32" 
                    SortExpression="EffID"
                     ReadOnly="true" Visible="False">
                 </telerik:GridBoundColumn>
                
                <telerik:GridBoundColumn 
                    DataField="PM" 
                    HeaderText="PM" 
                    UniqueName="PM" 
                    SortExpression="PM"
                     ReadOnly="true">
                </telerik:GridBoundColumn>
                <telerik:GridBoundColumn 
                    DataField="AcctUnit" 
                    HeaderText="AU" 
                    SortExpression="AcctUnit" 
                    UniqueName="AcctUnit"
                    ReadOnly="false">
                </telerik:GridBoundColumn>
                
                <telerik:GridBoundColumn 
                    DataField="Activity" 
                    HeaderText="Activity" 
                    SortExpression="Activity" 
                    UniqueName="Activity" DataType="System.Int32"
                    ReadOnly="false">
                </telerik:GridBoundColumn>
                <telerik:GridBoundColumn 
                    DataField="Description" 
                    HeaderText="Project" 
                    SortExpression="Description" 
                    UniqueName="Description"
                     ReadOnly="true"
                     >
                    <ItemStyle Width="250px" />
                </telerik:GridBoundColumn>
             
                 <telerik:GridBoundColumn
                    DataField="EndDate" 
                    DataType="System.DateTime" 
                    DataFormatString="{0:d}"
                    HeaderText="End Date" 
                    SortExpression="EndDate" 
                    UniqueName="EndDate"
                    ReadOnly="true">
                </telerik:GridBoundColumn>
             
                 <telerik:GridTemplateColumn DataField="EffPct" DataType="System.Decimal" 
                     HeaderText="Previous LDT Effort %" SortExpression="EffPct" UniqueName="EffPct"
                     HeaderStyle-Width="80px" >
                     <HeaderTemplate>
                        <asp:Label runat="server" ID="lblCurrentLDTDate" Text="Current LDT Date" Visible="true">
                        </asp:Label>
                     </HeaderTemplate>
                     <ItemTemplate
                     >
                         <asp:Label 
                            ID="lblEffPct" 
                            runat="server" 
                            Text='<%# Eval("EffPct") %>'
                            Font-Bold="true"
                            ForeColor="Blue"
                            ></asp:Label>
                          <%--<telerik:RadNumericTextBox
                            ID="txtEffPct"
                            runat="server"
                            NumberFormat-DecimalDigits="2"
                            DbValue='<%# Eval("EffPct") %>'
                            Enabled="false"
                            Width="50px"
                            >
                            </telerik:RadNumericTextBox>--%>
                           
                     </ItemTemplate>
                     <EditItemTemplate>
                         <asp:TextBox 
                            ID="EffPctTextBox" 
                            runat="server" 
                            Text='<%# Bind("EffPct") %>'
                            onKeyDown="if(event.keyCode==13) event.keyCode=9;"></asp:TextBox>
                     </EditItemTemplate>
                     <FooterTemplate>
                        <asp:Label ID="footCurrentLDTSum" Text ="Curr LDT Sum" runat="server" Font-Bold="true"></asp:Label>
                     </FooterTemplate>
                 </telerik:GridTemplateColumn>
                 <telerik:GridTemplateColumn 
                                UniqueName="tempLDTEff1" 
                                DataType="System.DateTime"
                                HeaderText="LDT1 Effective Date" 
                                Reorderable="False" 
                                Resizable="False" 
                                ShowSortIcon="False"
                                HeaderStyle-Width="80px"
                                DataField="LDT1EffPct" 
                                ReadOnly="True"
                                >
                               <HeaderTemplate>
                               
                                    <asp:Label 
                                        ID="headLDTEff1"  
                                        Text ="LDT1 Effective Date" 
                                        runat="server">
                                    </asp:Label><br />
                                     
                                <asp:TextBox 
                                    ID="txtNewLDTDate1" 
                                    runat="server"
                                    ToolTip="Type new date to add an LDT.  Can accept 'mm/dd/yyyy' and 'm/d/yyyy' formats"
                                    OnTextChanged="txtNewLDTDate1_OnTextChanged"
                                    AutoPostBack="true"
                                    Font-Bold="true"
                                    onKeyDown="if(event.keyCode==13) event.keyCode=9;"
                                    Width="75px"
                                   >
                                 </asp:TextBox>
                                 <asp:Button 
                                    ID ="btnLDT1Delete" 
                                    runat="server" 
                                    Text ="Delete LDT1" 
                                    Visible="false" 
                                    OnClick="btnLDT1Delete_Click" 
                                    BorderStyle="None"
                                    Font-Underline="true"
                                    ForeColor="Blue"
                                    BackColor="Transparent"/>
                                <asp:RegularExpressionValidator 
                                    ID="regExtNewLDTDate1" 
                                    runat="server" 
                                    ErrorMessage="Invalid date format.  Can accept 'mm/dd/yyyy' and 'm/d/yyyy' formats"
                                    ControlToValidate="txtNewLDTDate1"
                                    Display="Static"
                                    ValidationExpression="^[0,1]?\d{1}\/(([0-2]?\d{1})|([3][0,1]{1}))\/(([1]{1}[9]{1}[9]{1}\d{1})|([2-9]{1}\d{3}))$">
                                </asp:RegularExpressionValidator>
                                <asp:Label 
                                    ID="lblLDT1" 
                                    runat="server">New LDT Effort %
                                </asp:Label>
                                </HeaderTemplate>
                                <ItemTemplate>                    
                                 <telerik:RadNumericTextBox
                                    runat="server"
                                    ID="txtLDT1Dt"
                                    DbValue='<%# Eval("LDT1EffPct") %>'
                                    OnTextChanged="TextChanged"
                                    AutoPostBack="true"
                                    onKeyDown="if(event.keyCode==13) event.keyCode=9;"
                                    Width="50px">
                                 </telerik:RadNumericTextBox>
                                 </ItemTemplate>
                                <FooterTemplate>
                                    <asp:Label ID="footLDTEff1" Text ="LDT1 Sum" runat="server" Font-Bold="true"></asp:Label>
                                </FooterTemplate>
                                <HeaderStyle Width="80px"></HeaderStyle>
                        </telerik:GridTemplateColumn>
                
               <telerik:GridBoundColumn 
                    HeaderText="Changed?" 
                    UniqueName="Changed1"
                    DataField="Changed1" 
                    SortExpression="Changed1"
                    ReadOnly="True"
                    >
                 </telerik:GridBoundColumn>
                 <%--<telerik:GridCheckBoxColumn 
                    DataField="Hold" 
                    DataType="System.Boolean" 
                    HeaderText="On Hold?" 
                    SortExpression="Hold" 
                    UniqueName="Hold"
                     ReadOnly="True">
                </telerik:GridCheckBoxColumn>--%>
                <telerik:GridTemplateColumn 
                                UniqueName="tempHold" 
                                Reorderable="False" 
                                Resizable="False" 
                                ShowSortIcon="False"
                                Visible="false"
                                >
                                
                                <HeaderTemplate>
                                    <asp:Label 
                                        ID="lblHold1"  
                                        Text ="On Hold?" 
                                        runat="server">
                                    </asp:Label>
                               </HeaderTemplate>    
                               <ItemTemplate> 
                        <asp:CheckBox ID="chkOnHold" 
                            runat="server"
                            AutoPostBack="False"  
                            Checked='<%# DataBinder.Eval (Container.DataItem,"Hold").ToString()!="True"?false:true %>' 
                            Enabled="false"/> 
                    </ItemTemplate>
                 </telerik:GridTemplateColumn>
                <telerik:GridBoundColumn 
                    DataField="HoldBy" 
                    HeaderText="Held By" 
                    SortExpression="HoldBy" 
                    UniqueName="HoldBy"
                     ReadOnly="true"
                     Visible="false">
                </telerik:GridBoundColumn>
                <telerik:GridTemplateColumn 
                                UniqueName="tempLDTEff2" 
                                Reorderable="False" 
                                Resizable="False" 
                                ShowSortIcon="False" ReadOnly="True"
                                >
                                
                                <HeaderTemplate>
                                    <asp:Label 
                                        ID="headLDTEff2"  
                                        Text ="LDT2 Effective Date" 
                                        runat="server">
                                    </asp:Label>
                                   <%-- <asp:LinkButton 
                                    ID="lnkEditLDT2Date"
                                    Text="Edit" 
                                    CommandName="" 
                                    Runat="server"
                                    OnClick="ToggleDateEdit"
                                    Visible="true"
                                    >
                                    
                                 </asp:LinkButton>
                                 <asp:Button 
                                    ID="btnEditLDT2Date" 
                                    runat="server" 
                                    Text="Edit" 
                                    OnClick="ToggleDateEdit"
                                    BorderStyle="Groove"
                                    BorderColor="Blue"
                                    AutoPostBack="true"/> --%>
                                 
                                    <asp:Label 
                                        ID="lblLDTDate2"  
                                        Text =" " 
                                        runat="server">
                                    </asp:Label>
                                    <asp:TextBox 
                                    ID="txtNewLDTDate2" 
                                    runat="server"
                                    ToolTip="Type new date to add an LDT.  Can accept 'mm/dd/yyyy' and 'm/d/yyyy' formats"
                                    OnTextChanged="txtNewLDTDate2_OnTextChanged"
                                    AutoPostBack="true"
                                    Font-Bold="true"
                                    onKeyDown="if(event.keyCode==13) event.keyCode=9;"
                                    Width="75px">
                                 </asp:TextBox>
                                 <asp:Button 
                                    ID ="btnLDT2Delete" 
                                    runat="server" 
                                    Text ="Delete LDT2" 
                                    Visible="false" 
                                    OnClick="btnLDT2Delete_Click" 
                                    BorderStyle="None"
                                    Font-Underline="true"
                                    ForeColor="Blue"
                                    BackColor="Transparent"/>
                                    <asp:RegularExpressionValidator 
                                        ID="regExtNewLDTDate2" 
                                        runat="server" 
                                        ErrorMessage="Invalid date format.  Can accept 'mm/dd/yyyy' and 'm/d/yyyy' formats"
                                        ControlToValidate="txtNewLDTDate2"
                                        Display="Static"
                                        ValidationExpression="^[0,1]?\d{1}\/(([0-2]?\d{1})|([3][0,1]{1}))\/(([1]{1}[9]{1}[9]{1}\d{1})|([2-9]{1}\d{3}))$">
                                    </asp:RegularExpressionValidator>
                                    <asp:Label 
                                        ID="lblLDT2" 
                                        runat="server"
                                        >New LDT Effort %
                                    </asp:Label>
                                </HeaderTemplate>
                                
                                <ItemTemplate>                    
                                    <telerik:RadNumericTextBox 
                                        ID="txtLDT2Dt"
                                        runat="server"
                                        AutoPostBack="true" 
                                        NumberFormat-DecimalDigits="2"
                                        OnTextChanged="TextChanged"
                                        DbValue='<%# Eval("LDT2EffPct") %>'
                                        onKeyDown="if(event.keyCode==13) event.keyCode=9;"
                                        Width="50px">
                            
                                        </telerik:RadNumericTextBox> 
                            
                                 </ItemTemplate>
                                
                                <FooterTemplate>
                                    <asp:Label ID="footLDTEff2" Text ="LDT2 sum" runat="server" Font-Bold="true"></asp:Label>
                                </FooterTemplate>


                                <FooterStyle Font-Bold="True" />
                            <HeaderStyle Width="80px"></HeaderStyle>
                            </telerik:GridTemplateColumn>
                
                <telerik:GridBoundColumn 
                    DataField="Changed2" 
                    HeaderText="Changed?" 
                    SortExpression="Changed2" 
                    UniqueName="Changed2"
                    ReadOnly="true">
                </telerik:GridBoundColumn>
                <telerik:GridTemplateColumn 
                    UniqueName="tempOnHold2" 
                    HeaderText="On Hold?"
                    Visible="false"> 
                    <ItemTemplate> 
                        <asp:CheckBox ID="chkOnHold2" 
                            runat="server"
                            AutoPostBack="False"  
                            Checked='<%# DataBinder.Eval (Container.DataItem,"Hold2").ToString()!="True"?false:true %>' 
                            Enabled="false"/> 
                    </ItemTemplate> 
                </telerik:GridTemplateColumn>
                <%--<telerik:GridCheckBoxColumn 
                    DataField="Hold2" 
                    DataType="System.Boolean" 
                    HeaderText="On Hold?" 
                    SortExpression="Hold" 
                    UniqueName="Hold2"
                     ReadOnly="True">
                </telerik:GridCheckBoxColumn>--%>
                <telerik:GridBoundColumn 
                    DataField="HoldBy2" 
                    HeaderText="Held By" 
                    SortExpression="HoldBy2" 
                    UniqueName="HoldBy2"
                     ReadOnly="true"
                     Visible="false">
                </telerik:GridBoundColumn>
                
            </Columns>
            <EditFormSettings  
                ColumnNumber="2" 
                CaptionDataField="Activity" 
                CaptionFormatString="Edit properties of Product {0}">
                   <FormTableItemStyle Wrap="False"></FormTableItemStyle>
                    <FormCaptionStyle ></FormCaptionStyle>
                    <FormMainTableStyle GridLines="None" CellSpacing="0" CellPadding="3" BackColor="White"
                        Width="100%" />
                    <FormTableStyle CellSpacing="0" CellPadding="2" Height="110px" BackColor="White" />
                    <FormTableAlternatingItemStyle Wrap="False"></FormTableAlternatingItemStyle>
                    <EditColumn ButtonType="ImageButton" InsertText="Insert Order" UpdateText="Update record"
                        UniqueName="EditCommandColumn1" CancelText="Cancel edit">
                    </EditColumn>
                    <FormTableButtonRowStyle HorizontalAlign="Right" ></FormTableButtonRowStyle>
                </EditFormSettings>
</MasterTableView>
    </telerik:RadGrid>
0
Kostadin
Telerik team
answered on 22 May 2014, 11:01 AM
Hi Brad,

I have already answered your support ticket, so I would recommend you to continue our conversation there.

Regards,
Kostadin
Telerik
 

Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

 
Tags
Grid
Asked by
Brad
Top achievements
Rank 1
Answers by
Kostadin
Telerik team
Brad
Top achievements
Rank 1
Share this question
or