Creating custom gridview (inheriting from gridview class)

Discussion in 'ASP .Net' started by =?Utf-8?B?V2ViTWF0cml4?=, Oct 21, 2006.

  1. 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
    =?Utf-8?B?V2ViTWF0cml4?=, Oct 21, 2006
    #1
    1. Advertising

  2. 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
    >
    =?Utf-8?B?RGFsZQ==?=, Oct 22, 2006
    #2
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Joel Barsotti
    Replies:
    4
    Views:
    2,179
    Joel Barsotti
    Oct 30, 2003
  2. Replies:
    1
    Views:
    393
    Kevin Spencer
    Aug 17, 2005
  3. Mark
    Replies:
    1
    Views:
    1,070
    Arvind
    Apr 28, 2004
  4. Richard Lee
    Replies:
    4
    Views:
    1,048
    James Kanze
    Mar 6, 2008
  5. Replies:
    4
    Views:
    398
Loading...

Share This Page