duckmike
duckmike

Reputation: 1036

Inheriting from asp:GridView

I have several pages that all have a GridView control. Within that control there are several events that need to be implemented (OnRowDataBound, OnEditing, etc...)

Any suggestions as far as inheriting from a page that will force me (virtual functions) to implement each of these events? I can't visualize how that would look because of the GridView being a control. How do I inherit from a control?

Upvotes: 3

Views: 1357

Answers (1)

dash
dash

Reputation: 91520

A common way of doing this is to contain your GridView in a UserControl

If you place your grid on the user control, and subscribe to all the events there, then you can reuse this implementation anywhere you want in the application - you are essentially just wrapping the user control with the functionality you want, and then reusing this wrapper everywhere.

The neat thing is that you only have to write the wire-up code once.

That's what I think you want to do.

If you want to extend or handle these events outside the usercontrol, though, you'll need to reimplement them (i.e. add your own event handlers and let those bubble up).

You can't force anyone to subscribe to your events though.

If you wanted to force an implementation of the events then you can put the events on an interface, and implement that interface on the class or control you add it to. As the events are on the interface, you will not be able to compile until the interface has been implmented.

If you have a specific use case I can try to add an example.

Upvotes: 2

Related Questions