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

[Solved] 'null' is null or not an object.

2 Answers 128 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Johan Frisell
Top achievements
Rank 1
Johan Frisell asked on 12 Mar 2010, 03:02 PM
Hi,

I'm implementing Telerik radgrid in Sharepoint.

I use the NeedDataSource event to populate my grid. I get the data through linqtosql in the following manner:

    RadGrid1.DataSource = handler.Find(); ->

    

public IList<Company1.Grid.Data.DataTransferObjects.KravDTO> Find()  
        {  
            using (Company1LinqDSDataContext context = new Company1LinqDSDataContext())  
            {  
 
                return (from k in context.Kravs  
                        select new Company1.Grid.Data.DataTransferObjects.KravDTO()  
                        {  
                            Anr=k.anrr,  
                            ID=k.ID,  
                            Kund=k.Kund  
 
                        }).ToList();  
 
            }  
             
              
        } 

Hence the RadGrid is populated with an IList as datasource.

This works fine! However the filtering and paging functions only work once every refresh. E.g: Navigate to the page containing the RadGrid. Filter/change page or anything like that and the filtering and ability to change number of items per page stops working.
The paging itself (clicking the navigation) and sorting still works.

If i refresh the page the filtering and "number per page" function works again until the next action.

The only error message i get is: "'null' is null or not an object".

My .ascx code:

            <telerik:RadAjaxManager ID="RadAjaxManager1" runat="server">  
                <AjaxSettings> 
                    <telerik:AjaxSetting AjaxControlID="RadGrid1">  
                        <UpdatedControls> 
                            <telerik:AjaxUpdatedControl ControlID="RadGrid1" /> 
                        </UpdatedControls> 
                    </telerik:AjaxSetting> 
                </AjaxSettings> 
            </telerik:RadAjaxManager> 
            <telerik:RadGrid ID="RadGrid1" Width="97%"   
             AllowPaging="True" PageSize="25" runat="server" AllowFilteringByColumn="True" AllowSorting="True" 
             OnNeedDataSource="RadGrid1_NeedDataSource" GridLines="None">  
              <MasterTableView Width="100%" /> 
              <PagerStyle Mode="NextPrevAndNumeric" /> 
                <FilterMenu EnableTheming="True">  
                    <CollapseAnimation Duration="200" Type="OutQuint" /> 
                </FilterMenu> 
            </telerik:RadGrid> 

Any ideas?

2 Answers, 1 is accepted

Sort by
0
Nikolay Rusev
Telerik team
answered on 16 Mar 2010, 07:29 AM
Hello Johan,

I assume you are missing the code demonstrates on the following help article that enables you to use ASP.NET AJAX in MOSS:
http://www.telerik.com/help/aspnet-ajax/create-ajax-enabled-sharepoint-webpart-radcontrols.html

/the code in question/
01.protected override void OnInit(EventArgs e)
02.{
03.   base.OnInit(e);
04.   Page.ClientScript.RegisterStartupScript(typeof(Web_Part1), this.ID, "_spOriginalFormAction = document.forms[0].action;_spSuppressFormOnSubmitWrapper=true;", true);
05.   if (this.Page.Form != null)
06.   {
07.       string formOnSubmitAtt = this.Page.Form.Attributes["onsubmit"];
08.       if (!string.IsNullOrEmpty(formOnSubmitAtt) && formOnSubmitAtt == "return _spFormOnSubmitWrapper();")
09.       {
10.           this.Page.Form.Attributes["onsubmit"] = "_spFormOnSubmitWrapper();";
11.       }
12.   }
13.}


Kind regards,
Nikolay
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.
0
Johan Frisell
Top achievements
Rank 1
answered on 16 Mar 2010, 08:54 AM
Hi,

Thanks for your reply. I didn't miss that part, however I missed the following line:

 

this.Page.Items.Add(typeof(RadAjaxManager), ajaxManager);

 


This made me add the manager from C# and suddenly it worked.

Here's what fixed it:

Panel panel = new Panel();  
            panel.ID = "Panel1";  
            this.Controls.Add(panel);  
 
            panel.Controls.Add(RadGrid1);  
 
            RadAjaxManager ajaxManager = RadAjaxManager.GetCurrent(this.Page);  
            if (ajaxManager == null)  
            {  
                ajaxManager = new RadAjaxManager();  
                ajaxManager.ID = "RadAjaxManager1";  
                Controls.Add(ajaxManager);  
                this.Page.Items.Add(typeof(RadAjaxManager), ajaxManager);  
            }  
            ajaxManager.AjaxSettings.AddAjaxSetting(RadGrid1, panel); 
Tags
Grid
Asked by
Johan Frisell
Top achievements
Rank 1
Answers by
Nikolay Rusev
Telerik team
Johan Frisell
Top achievements
Rank 1
Share this question
or