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

Event Handling for Programmatically-created grid

3 Answers 115 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Mike
Top achievements
Rank 1
Mike asked on 09 Feb 2011, 10:37 PM
I've hit a dilemma that I hope has an obvious answer that I've overlooked.

I am creating a radgrid completely in the code-behind (page_init) and adding it to a place-holding panel in my page.  Since I want to do advance databinding and will need to handle the NeedDataSource event, I expected to then create a handler for it in the code-behind as well.

Since the control isn't in the .aspx page, there is no object reference for it during the design-time programming of the code-behind and I get compilation errors for a function that says it is handling an event for a control that doesn't yet exist.

Is there a way around or through this problem?

Mike

3 Answers, 1 is accepted

Sort by
0
Nikolay Rusev
Telerik team
answered on 10 Feb 2011, 08:43 AM
Hello Mike,

I am not sure I fully understand your question. Could you please explain a bit more?

Best wishes,
Nikolay
the Telerik team
Browse the vast support resources we have to jump start your development with RadControls for ASP.NET AJAX. See how to integrate our AJAX controls seamlessly in SharePoint 2007/2010 visiting our common SharePoint portal.
0
Mike
Top achievements
Rank 1
answered on 10 Feb 2011, 05:03 PM
I am creating a radgrid in the page_init handler.  It does not exist in the .aspx page at all.  When I have constructed the grid (added all the columns, etc.) I add it to a panel placeholder that *is*I in the .aspx page.

I would also like to handle the grid's events (NeedDataSource and/or Databinding, etc.) so I was ready to create several functions that would handle those events.  When I create those functions, the top line of them looks a little like:

Protected Sub MyRadGrid_DataBind (ByVal sender As Object, ByVal e As EventArgs) _
Handles MyRadGrid.Databinding

Because the MyRadGrid grid is not created until runtime, Visual Studio doesn't like there being a function that is trying to handle an event for an object that isn't defined in the .aspx file.

How shall I go about handling events for the grid that I am constructing completely in the code-behind?

Not sure if that is clearer, or not.  ;^)

Mike
0
Nikolay Rusev
Telerik team
answered on 16 Feb 2011, 09:32 AM
Hello Mike,

This is how you should add handler event programmatically:
http://msdn.microsoft.com/en-us/library/7taxzxka%28VS.80%29.aspx

Greetings,
Nikolay
the Telerik team
Browse the vast support resources we have to jump start your development with RadControls for ASP.NET AJAX. See how to integrate our AJAX controls seamlessly in SharePoint 2007/2010 visiting our common SharePoint portal.
Tags
Grid
Asked by
Mike
Top achievements
Rank 1
Answers by
Nikolay Rusev
Telerik team
Mike
Top achievements
Rank 1
Share this question
or