Members

Technology Zones

Articles

Hosted By

MaximumASP

Info

Rated
Read 119,940 times

Contents

Downloads

Related Categories

Building a Full-Featured Custom DataGrid Control - Introduction

DMarko1

Introduction

.NET, among its other amazing features, allows developers and programmers a rich platform with the capability to build custom controls deriving from already common base server controls, i.e. The Datagrid, the most commonly used and full-featured server control in .NET. One of the key components of .NET is OOP or Object-Oriented Programming, that focuses on creating reusable "black box" code enabling collective reuse throughout a website, significantly reducing development time when any changes have to be made affecting this one control. To gather a good grasp on this, take the time and read The Quick and Dirty .NET Guide to C#/VB Object-Oriented Programming.

In this article, we will examine and implement these very features and demonstrate how you can build your very own Datagrid control component, one that you will be able to customize, and more importantly reuse. Based on this ability, you will then end up with one powerful control that will have many implementations, from which you could learn about creating almost any other types of custom controls.

Now, some may question why would you attempt such a thing or why not simply use the common Datagrid? Well, good question! The quick and direct answer is reusability. Although requiring a lot more skill to create, the more all-inclusive answer would be custom controls promote lightly coded pages making for a lot less code to debug, offer greater flexibility, and more importantly, completely protected your code from anyone poking around.

Our example discussed here could easily be contained with the confines of a code-behind file, but this would usurp the latter aforementioned paradigms we have illustrated. With a custom control, you have a lot of power and control over what you render to the user or even restrict.

Having said that, this article will ultimately enable you to create a .NET page, incorporating a search form, with a pageable, and excitedly so a cacheable Datagrid custom control. Furthermore, learn various methods of interacting with your control, and learn how to assign and retrieve values from it as well!

Therefore, in this article we'll be learning how to:

  1. Create a .NET search page that will contain our custom control
  2. Learn how code-behind and compiling works
  3. Actually build our customizable Datagrid control class
  4. Demonstrate the ease of assigning and retrieving custom values to our control
  5. Enhance our control's behavior paging capabilities and the ability to displaying page and result numbers
  6. Demonstrate how to cache our Datagrid for added performance and scalability, all from within our control!
  7. Finally, show you how to enhance our Datagrid with four cool enhancements.

In turn, our result will be a page with no client side code or methods, only contain our code-behind reference and custom control DLL that we have created and compiled. After you finish this article, you will have amassed enough information in giving you the ability to create a custom server control class, and some great ideas to take what is here and expand even further. We are going to cover a lot of ground, but don't worry. In the end, you will end up having a number of solid techniques at your disposal for many various scenarios that may arise in the future.

Nevertheless, not to leave out any RAD VS.NET programmers, I have included this entire example as a C# VS.NET project solution, that includes the .aspx webform page containing our registered dll directive, and our C# code-behind that contains our custom datagrid methods that provide our UI page's interaction with our custom Datagrid control, and with the functionality we've set up when searching.

So with that said, let's get to it then.

Dimitrios, or Jimmy as his friends call him, is a .NET developer/architect who specializes in Microsoft Technologies for creating high-performance and scalable data-driven enterprise Web and desktop applications. Till now Jimmy has authored nearly two dozen .NET articles, published on Dot Net Junkies, 4 Guys From Rolla, Sitepoint, MSDN Academic Alliance, Developers.NET, The Official Microsoft ASP.NET Site, and here on Developer Fusion, covering various unique and advanced techniques on .NET.

Comments

  • Re: [4676] Building a Full-Featured Custom DataGrid Control-Paging not working

    Posted by adwivedi1 on 09 Oct 2006

    Hi,

    I am building a ASP .NET composite control containing a datagrid during which I am 
    finding a problem while paging of the grid.

    The problem is for example if I am having three pa...

  • Building Custom Datagrid control

    Posted by hells_1999 on 02 Feb 2006

    I build my own custom datagrid control using the code from your site.

    I used this control as a reference in another aspx page at you have mentioned in your article.
    I have 400 total number of rec...

  • Posted by wrocca on 22 Dec 2005

    [quote][1]Posted by [b]taxiturner[/b] on 3 May 2005 10:25 PM[/1]
    LiteralControl lc = (LiteralControl) sender;
    DataGridItem container = (DataGridItem) lc.NamingContainer;
    lc.Text = ((DataRowView) co...

  • unable to update and sort on click

    Posted by myselfhemant on 22 Nov 2005

    I have created a Custom control using your article but i am having problem in sorting and update
    as i use a class which implements itemplate interface for this and create the function for update and...

  • selecting multiple items in a checkbox from a dat

    Posted by sneha123 on 31 Oct 2005

    There will be some 20 questions and for each question there will be 4 choices.what i want to do is to select multiple answers by clicking the checkbox. i m using asp.net,vb.net
    pls help me

    we ha...