Creating custom gridview (inheriting from gridview class)

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hi,

I started a new web application which so far has several grdiviews
displaying data.
I find myself reimplementing the same logic (copy/pasting really) in grid's
event ItemDataBound and RowCreated and Sorting events to add certain effects.
For example inserting sorting direction image to the column header.
I want to create one custom grid view that implement all this logic to be
reused through out this app, so I wont need to copy paste code when adding a
new grid.
I know that I need to inherit from gridview class, in what method to I add
handlers for the events, do I need to override any methods? Any articles or
code samples ?

Thank you
 
There are actually a couple opprtunities for inheritance. Some of the
functionality you describe, for instance adding images for the sort column
headers, can be done several ways. You can create a user control wrapping
the GridView and add them in the OnInit method or Page_Load method.
Alternitavely, you can create a web custom control extending GridView and add
the functionality either in a public method or property or you can initialize
the common functionality in a method called by the constructor.

Other things you mention, such as adding event handlers, can't really be
handled in the extended control but, rather, should be handled in a
subclassed consumer of the control. For instance in your MasterPage or a
base page that extends System.Web.UI.Page. Your application pages then would
extend your custom base page rather than the default behavior of extending
System.Web.UI.Page directly.

HTH

Dale
 
Back
Top