RadGrid OnNeedDataSource error
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;
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
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
);
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
Scott,
Darn. Can you share the template of your user control? I'd like to take a peek at that next.
Thanks,
Chris
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
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