Building a DataGrid Helper Control For ASP.NET 1.x: Part 1
page 3 of 5
by Li Chen
Average Rating: This article has not yet been rated.
Views (Total / Last 10 Days): 25116/ 83

Create a DataGrid Helper Control

[Download Code]
There are several methods to enhance the functionality of an existing control: to inherit from the control, to create a wrapper for the control or write an extender or helper class. We will use the last method because it preserves the design-time functionality of the DataGrid control.

The DataGridHelper.cs file in the WebDataControls project contains the code for the DataGridHelper control. The DataGridHelper control has a DataGrid property that can be used to attach a DataGridHelper control to a DataGrid control. The DataGridHelper then handles the SortCommand and IndexChanged events of the DataGrid so that users of the control do not have to handle these events. The DataGridHelper also handled the Page_Load type functionality in the OnPreRender event of the control. We use the OnPreRender event because it fires after the controls states are already restored but before the page is rendered.

The DataGridHelper control exposes a single event called LoadData. The users of DataGridHelper must respond to this event to get the data source and set it to the DataSource property of the event argument.

The DataGridHelper control also has a few additional properties that allow fine tuning its behavior:

Property Purpose
AlternateSortDirection Alternate the sort direction on subsequent clicks of the same column header
AutoSortDataView If this property is true and the data source is a DataSet, DataTable or DataView, the DataGridHelper control will sort the data automatically
SortExpression The current sort expression. This property is useful when the user of the control wants to sort the data themselves in the LoadData event.
ResetPageIndexOnSorting If this property is True, the control will reset the page index whenever the sort expression is changed

The DataGridHelper control also exposes a method, GridLoad. We need to call this method only if we have a post-back from another control and we want to refresh the data in response to the change.

In the next section, we will show how to use the DataGridHelper control.

View Entire Article

User Comments

Title: DataGrid   
Name: Anita
Date: 2007-07-30 2:01:28 PM
Very Good
Title: Confusing   
Name: Anees
Date: 2006-10-05 1:04:44 AM
Its confusing for Begginers.
Title: Atish.netExpress   
Name: Atish J
Date: 2006-09-01 6:05:32 AM
Ver nice .......!
Title: datagrid   
Name: shailendra
Date: 2006-09-01 2:18:27 AM
Title: Good   
Name: Prashant Raizada
Date: 2006-07-27 4:40:54 AM
Good job!!!
Title: Testing Form   
Name: BinDev1998
Date: 2004-09-21 11:53:35 PM
This is Cool!
Title: good!   
Name: Region
Date: 2004-08-09 1:59:31 AM
Is Like My Grid
Title: NICE   
Name: Raghuraman
Date: 2004-08-07 3:12:19 AM
a nice walk thru
Title: Not Bad   
Name: Tarzan from Zimbava
Date: 2004-08-07 2:46:39 AM
It's a good article for Asp starters
Title: good   
Name: gayathri
Date: 2004-08-07 1:41:33 AM
Title: good   
Name: ramu
Date: 2004-06-28 4:15:35 AM
good article

Product Spotlight
Product Spotlight 

Community Advice: ASP | SQL | XML | Regular Expressions | Windows

©Copyright 1998-2020  |  Page Processed at 2020-04-03 1:09:39 AM  AspAlliance Recent Articles RSS Feed
About ASPAlliance | Newsgroups | Advertise | Authors | Email Lists | Feedback | Link To Us | Privacy | Search