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

RadGrid - Error between EditCOmmand and ItemDataBound

2 Answers 134 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Michael
Top achievements
Rank 1
Michael asked on 07 Jul 2008, 10:16 PM
I have a RadGrid where after clicking "edit" I get the infamous "Object reference not set to an instance of an object" error.

I am using LinqDataSource that has EnableUpdate="true"

Here is the Grid source:

<telerik:RadGrid ID="rgProducts" runat="server"   
    AllowFilteringByColumn="True" DataSourceID="ldsProducts" 
    AllowPaging="True" AllowSorting="True" Skin="Vista" PageSize="20" 
    oncancelcommand="rgProducts_CancelCommand" Width="99%" 
    oneditcommand="rgProducts_EditCommand" OnItemDataBound="rgProducts_ItemDataBound" 
    onupdatecommand="rgProducts_UpdateCommand" AutoGenerateColumns="False" > 
      
    <PagerStyle Height="28px" Mode="NextPrevAndNumeric" Position="Bottom"/>  
      
    <mastertableview allowfilteringbycolumn="True" allowpaging="True" DataKeyNames="ProductId"   
        allowsorting="True" TableLayout="Fixed" DataSourceID="ldsProducts">  
      
        <Columns> 
            <telerik:GridEditCommandColumn> 
                <HeaderStyle Width="5%" /> 
            </telerik:GridEditCommandColumn> 
            <telerik:GridBoundColumn DataField="ProductId" DataType="System.Int32"   
                HeaderText="Id" ReadOnly="True" SortExpression="ProductId"   
                UniqueName="ProductId">  
                <HeaderStyle Width="15%" /> 
            </telerik:GridBoundColumn> 
            <telerik:GridTemplateColumn HeaderText="Type" SortExpression="ProductType.ProductTypeName" CurrentFilterFunction="Contains" AutoPostBackOnFilter="True" > 
                <ItemTemplate> 
                    <%#Eval("ProductType.ProductTypeName")%> 
                </ItemTemplate> 
                <HeaderStyle Width="30%" /> 
                <ItemStyle Wrap="false" /> 
            </telerik:GridTemplateColumn> 
            <telerik:GridBoundColumn DataField="ProComProductCode"   
                HeaderText="Product Code" SortExpression="ProComProductCode"   
                UniqueName="ProComProductCode" CurrentFilterFunction="Contains" AutoPostBackOnFilter="True">  
                <HeaderStyle Width="15%" /> 
                <ItemStyle Wrap="false" /> 
            </telerik:GridBoundColumn> 
            <telerik:GridBoundColumn DataField="ProductName" HeaderText="Name"   
                SortExpression="ProductName" UniqueName="ProductName" CurrentFilterFunction="Contains" AutoPostBackOnFilter="True">  
                <HeaderStyle Width="35%" /> 
                <ItemStyle Wrap="false" /> 
            </telerik:GridBoundColumn> 
        </Columns> 
          
        <editformsettings editformtype="Template">  
            <formtemplate> 
                <!-- left this code out - very large --> 
            </formtemplate> 
            <popupsettings scrollbars="None" /> 
        </editformsettings> 
 
    </mastertableview> 
</telerik:RadGrid> 

When I set a breakpoint in the EditCommand event, the one line of code there that is hiding the edit column works just fine, then the code never reaches the breakpoint I have in the ItemDataBound event.  ANy ideas what could be happenning between these two events?  I tried stepping through beyond the EditCommandEvent, but it was stepping through the LINQ designer code.

Thoughts?

Michael

2 Answers, 1 is accepted

Sort by
0
Michael
Top achievements
Rank 1
answered on 08 Jul 2008, 02:34 AM
Here's a little more information as I continue to dig into this...

My ItemDataBound event begins with the following line:

if
(e.Item is GridEditFormItem && e.Item.IsInEditMode)

If  I put a breakpoint right there after the EditCommand event is fired, I will hit this breakpoint once for each row in the table, but it never goes any further in the event code.  The if statement is never satisfied.  Eventually I just get back the error I mentioned above in the browser.  It is almost as if the RadGrid is looking for the row to edit, resulting from the edit link being clicked, but never finds, or overestimates, how many rows to traverse and ends up trying to get an additional record when no more are left??? Totally guessing, but figured to post this information.  I will post more, but please look into this issue.  There is no code of mine between these two events.

Thanks!

Michael
0
Michael
Top achievements
Rank 1
answered on 08 Jul 2008, 03:57 AM
Please ignore.  I figured out the problem after a lot of line by line commenting.  As it turns out, I was binding linq data within the ascx file to a checkbox - and apparently, I was not doing it correctly.  If I commented out that line, everything worked.  I need to see how to do this correctly, but at least I was able to see what was causing the issue.

I literally just started using LINQ.  The sometimes cryptic error messages really get me sometimes.  Oh well...

Sorry to point the anywhere but at me!

Michael
Tags
Grid
Asked by
Michael
Top achievements
Rank 1
Answers by
Michael
Top achievements
Rank 1
Share this question
or