Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 209
duckmike Avatar asked Apr 20 '26 01:04

duckmike


1 Answers

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.

like image 158
dash Avatar answered Apr 22 '26 15:04

dash



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!