+1-888-365-2779
Try Now
More in this section

Forums / Developing with Sitefinity / RadGrid OnNeedDataSource error

RadGrid OnNeedDataSource error

7 posts, 0 answered
  1. Scott MacDonald
    Scott MacDonald avatar
    29 posts
    Registered:
    08 Mar 2006
    26 Apr 2013
    Link to this post
    Hi, I have created a simple Module Builder module and trying to bind it to a RadGrid but getting the attached screenshot error. Can anyone assist? I have the RadGrid1_NeedDataSource event in the code behind so I don't understand why it's complaining.

            protected void RadGrid1_NeedDataSource(object source, Telerik.Web.UI.GridNeedDataSourceEventArgs e)
            {
                // use your variable here
                var myCollection = RetrieveCollectionOfCities();
                RadGrid1.DataSource = myCollection;
            }
  2. Stefani Tacheva
    Stefani Tacheva avatar
    718 posts
    Registered:
    21 Nov 2016
    26 Apr 2013
    Link to this post
    Hi,

    I have send you a working sample on the support ticket you have opened. You could share the solution with the community if you want.

    Greetings,
    Stefani Tacheva
    the Telerik team
    Do you want to have your say in the Sitefinity development roadmap? Do you want to know when a feature you requested is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
  3. Chris
    Chris avatar
    11 posts
    Registered:
    10 Mar 2011
    26 Apr 2013
    Link to this post
    Scott,

    If you are doing this from a widget template, you will need to assign the NeedDataSource event in your code behind before controls are rendered on the page. To do this - you need to get a reference back to your RadGrid in the widget template (because the template and code behind aren't directly linked).

    protected override void OnLoad(EventArgs e)
    {
        base.OnLoad(e);
        RadGrid1.NeedDataSource += RadGrid1_NeedDataSource;
    }
     
    protected void RadGrid1_NeedDataSource(object sender, GridNeedDataSourceEventArgs e)
    {
        // use your variable here
        var myCollection = RetrieveCollectionOfCities();
        RadGrid1.DataSource = myCollection;
    }
     
    protected virtual RadGrid RadGrid1
    {
        get
        {
            return this.Container.GetControl<RadGrid>("RadGrid1", true);
        }
    }


    I hope this helps!

    Thanks,

    Chris

  4. Scott MacDonald
    Scott MacDonald avatar
    29 posts
    Registered:
    08 Mar 2006
    26 Apr 2013 in reply to Chris
    Link to this post
    Hi Chris,

    Thanks a lot for responding. I'm actually creating my own user control instead of using the toolbox widget that automatically gets created upon module creation. I was hoping your suggestion would help but unfortunately it didn't, I'm still receiving the same error. If you have any other ideas I would greatly appreciate it.

    Thanks again,

    Scott
  5. Chris
    Chris avatar
    11 posts
    Registered:
    10 Mar 2011
    28 Apr 2013 in reply to Scott MacDonald
    Link to this post
    Scott,

    Darn. Can you share the template of your user control? I'd like to take a peek at that next.

    Thanks,

    Chris
  6. Scott MacDonald
    Scott MacDonald avatar
    29 posts
    Registered:
    08 Mar 2006
    30 Apr 2013 in reply to Chris
    Link to this post
    Hi Chris,

    I never could  get the OnNeedDataSource to work for whatever reason but I did happen to find that the Module Builder code reference actually gives the exact code I was looking for under "Integration example for a <moduleitemname>". It hits the database and brings back a collection of items and binds it to a radgrid, without the OnNeedDataSource though. So, I'm gathering that OnNeedDataSource is really only required in certain situations.

    Thanks again for your help,

    Scott 
  7. Victor Velev
    Victor Velev avatar
    1345 posts
    Registered:
    06 Jul 2015
    01 May 2013
    Link to this post
    Hello Scott,

    I am glad to hear that you managed to resolve the issue you are encountering with the help of the sample codes provided by the Module Builder. Still, there is a useful forum thread, which I believe may in some case be useful to you. I am copying the link here for your reference:

    http://www.sitefinity.com/developer-network/forums/developing-with-sitefinity-/pre-5-4-code-example-on-using-choice-field-to-filter-grid-in-frontend-usercontrol


    Kind regards,
    Victor Velev
    the Telerik team
    Do you want to have your say in the Sitefinity development roadmap? Do you want to know when a feature you requested is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
7 posts, 0 answered