My ASP knowledge base

Custom Server Control: build your own simple GridView

Posted by Jan on June 29, 2007

“This article consists of several pages describing the definition of a custom grid control. You can create your own controls in two ways:

  • User Controls (ascx-extention): a small part of a page that will be reused in your web pages.
  • Custom Server Controls: classes that will generate HTML. Custom Server Controls are compiled into DLL assemblies.

This example describes a Custom Server Control. This gives you total control over the HTML and makes it possible to add the control to your toolbox.

If you are interested in User Controls, see the following pages for more information:
http://www.15seconds.com/issue/020319.htm
http://quickstarts.asp.net/QuickStartv20/aspnet/doc/ctrlref/userctrl/default.aspx

The custom server control described in this article, is a simple databound grid. Easy to add to your web pages, for those cases where you do not need the extended features of the VS2005’s GridView. And you can modify this control to you own wishes.

This custom grid control is not a templated control. If you are interested in templated custom server controls, please see http://samples.gotdotnet.com/quickstart/aspplus/doc/webctrlauthoring.aspx for more information.

The custom grid control looks like this:

Custom Grid Control

You can add the control by adding a reference in your web page and define the grid’s parameters:

<%@ Register Assembly=”WITControlsLibrary” Namespace=”WITControlsLibrary” TagPrefix=”wit” %>

<wit:WITGrid ID=”WITGridExample” runat=”server”
    DataSourceID=”AccessDataSource1″
    DataKeyName=”participantID”
    ShowDeleteColumn=”True”
    ShowEditColumn=”True”
    ShowOrderColumn=”True”
    HighLightSelectedRow=”true”
    HighLightCssClass=”GridView-Highlight”
    EmptyGridCssClass=”GridView-Empty”
    NoRecordsText=”No records where found.”
    EnableViewState=”False”
    OnRowDataBound=”gridExample_OnRowDataBound”
    OnRowCommand=”gridExample_OnRowCommand”>
    <wit:BoundField CssClass=”grid-column-max” DataField=”participantName” HeaderText=”Name” />
    <wit:BoundField CssClass=”grid-column-medium” DataField=”participantEMail” HeaderText=”E-mail” />
    <wit:CheckBoxField CssClass=”grid-column-medium” DataField=”participantLocked” HeaderText=”Locked” />
</
wit:WITGrid>

The article is split up into different pages in order to avoid one very lengthy page. Click on one of the following items for more info, or click Next Page >> 

I hope these articles will help you further in building your own grid.

Regards, Jan

  Next Page >>

3 Responses to “Custom Server Control: build your own simple GridView”

  1. Rocket Software

    Useful, thank you!

  2. John said

    Used it with slight modifications and works fine thanks :)

  3. Somehow i missed the point. Probably lost in translation :) Anyway … nice blog to visit.

    cheers, Griddlecake.

Leave a Reply

XHTML: You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <pre> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>