RadGrid OnNeedDataSource error

Posted by Community Admin on 04-Aug-2018 14:06

RadGrid OnNeedDataSource error

All Replies

Posted by Community Admin on 26-Apr-2013 00:00

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;
       

Posted by Community Admin on 26-Apr-2013 00:00

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

Posted by Community Admin on 26-Apr-2013 00:00

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

Posted by Community Admin on 26-Apr-2013 00:00

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

Posted by Community Admin on 28-Apr-2013 00:00

Scott,

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

Thanks,

Chris

Posted by Community Admin on 30-Apr-2013 00:00

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 

Posted by Community Admin on 01-May-2013 00:00

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:

www.sitefinity.com/.../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

This thread is closed