471,582 Members | 1,529 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,582 software developers and data experts.

Creating custom gridview (inheriting from gridview class)

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

Oct 21 '06 #1
1 11567
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
--
Dale Preston
MCAD C#
MCSE, MCDBA
"WebMatrix" wrote:
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
Oct 21 '06 #2

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

10 posts views Thread by moondaddy | last post: by
reply views Thread by Nenefta | last post: by
reply views Thread by Louis-Pierre Dauphinais | last post: by
2 posts views Thread by Greg | last post: by
1 post views Thread by a | last post: by
1 post views Thread by Abdo Haji-Ali | last post: by
reply views Thread by XIAOLAOHU | last post: by
reply views Thread by leo001 | last post: by
reply views Thread by lumer26 | last post: by
reply views Thread by Vinnie | last post: by
1 post views Thread by lumer26 | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.