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:

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
- Getting started: adding the right resources, references and assembly information.
- Designing the ‘inner’ elements of the grid (the data columns: BoundField.cs, CheckBoxField.cs, etc.).
- The grid control itself (WITGrid.cs).
- The grid’s event arguments.
- The designer class (WITGridDesigner) that enables the grid to be shown in web page’s design view.
- Adding smart tags: the designer action list class.
- Add the control to your web page: The grid’s parameters and events explained.
- The source code of the control and an example
| Next Page >> |
This entry was posted on June 29, 2007 at 11:23 am and is filed under GridView, asp, compositecontrol, custom control, custom server control, designer, smart tags. You can follow any responses to this entry through the RSS 2.0 feed. You can leave a response, or trackback from your own site.
Yianni Ockley said
Rocket Software
Useful, thank you!
John said
Used it with slight modifications and works fine thanks
Griddlecake said
Somehow i missed the point. Probably lost in translation
Anyway … nice blog to visit.
cheers, Griddlecake.