Creating custom gridview (inheriting from gridview class)

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
 
G

Guest

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,995
Messages
2,570,230
Members
46,817
Latest member
DicWeils

Latest Threads

Top