Click here to Skip to main content
15,885,952 members
Articles / Web Development / ASP.NET
Article

ExtGridView

Rate me:
Please Sign up or sign in to vote.
4.79/5 (68 votes)
5 Dec 2005CPOL2 min read 830K   13.6K   214   180
A control which displays hierarchical data using the ASP.NET DataGrid or GridView control.

ExtGridView in action!

Introduction

This article presents a control which displays hierarchical data using the ASP.NET GridView control. This extension of the GridView control can also be used to display extended data details for a data row.

Using the code

The ExtGridView control can be used just like the regular ASP.NET GridView control (since it's inherited from GridView). The ExtGridView control will take care to displaying the expand/collapse button and also shows or hides the nested content.

But how should the nested content be added to the grid? The idea is simple. Because each row can have some related nested content, the ExtGridView control assumes that this content is placed in the last column of the grid. So the content from the last column will not be displayed as a regular column in the grid, but rather as the content which is displayed when the expand button is clicked.

In the sample project, the Customers table from the Northwind database is displayed using the ExtGridView control. The customer's orders are displayed in another ExtGridView as nested content. Finally, the Order details are displayed as nested content for the rows in the Orders grid. If it's necessary, when running the sample project, please modify the connection string in web.config.

Please notice that instead of the grid from the last column, you can place any other ASP.NET control (or HTML code) inside the ItemTemplate and the control will be displayed as nested content.

Points of Interest

Customizing the expand/collapse button's appearance

The ExtGridView control defines the following properties that can be used to customize the expand/collapse button appearance:

  • ExpandButtonCssClass - specifies the CSS class name that is used for the expand button.
  • CollapseButtonCssClass - specifies the CSS class name that is used for the collapse button.
  • ExpandButtonText - specifies the text for the expand button (default value is "+").
  • CollapseButtonText - specifies the text for the collapse button (default value is "-").

Note that you can specify HTML code as values for the ExpandButtonText and the CollapseButtonText properties. (This can be used as a workaround for the 'anchors with the background image flickering' bug in IE.)

HTML
<cc:ExtGridView runat="server" id="grid1" 
  ExpandButtonText="<img src='Images/expand.gif' alt='+' border='0' />" 
  CollapseButtonText="<img src='Images/collapse.gif' alt='-' border='0' />" ...

Hiding the expand/collapse button

Each row in the ExtGridView is actually an instance of the ExtGridViewRow class. So any object of type GridViewRow that is a row in an ExtGridView control can be converted to ExtGridViewRow. So, when you want to hide the expand/collapse button for a row in the ExtGridViewRow control, first convert the GridRow object to ExtGridViewRow and then you can use the ShowExpand property to specify if the expand/collapse button is visible or not.

C#
ExtGridViewRow row = grid.Rows[0] as ExtGridViewRow;
row.ShowExpand = false;

History

  • 2005-11-21 - First version release.
  • 2005-11-24 - Updated the expand/collapse button's behavior.
  • 2005-11-28 - Added the ExtDataGrid control which is supported by .NET 1.x.
  • 2005-12-05 - Added a sample project for using the ExtDataGrid control (.NET 1.1). Image 2

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Software Developer
Romania Romania
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions

 
GeneralRe: By default expand/collapse is turned off Pin
Ralph Willgoss20-Jun-08 19:00
Ralph Willgoss20-Jun-08 19:00 
GeneralRe: By default expand/collapse is turned off Pin
Steve Calkin26-Jun-08 2:56
Steve Calkin26-Jun-08 2:56 
AnswerRe: By default expand/collapse is turned off Pin
Steve Calkin4-Mar-09 2:43
Steve Calkin4-Mar-09 2:43 
GeneralTestGridControl - Invalid object name:Customers Pin
Ekjon12-May-08 8:20
Ekjon12-May-08 8:20 
QuestionFiltering option? Pin
DSPINNEY11-Apr-08 11:46
DSPINNEY11-Apr-08 11:46 
QuestionSORT option? Pin
licentiat24-Mar-08 12:44
licentiat24-Mar-08 12:44 
GeneralError is thrown as 'ExtGridView' is not a known element. Pin
senthil kumarKR23-Jan-08 0:28
senthil kumarKR23-Jan-08 0:28 
GeneralCannot see Expand Button Pin
shetty7731-Oct-07 5:43
shetty7731-Oct-07 5:43 
Hi,
I have data bound the outter grid to a dataset and can see the details displayed. I cannot see the Expand button or the inner grid.
please help..
GeneralSortable GridViewTree Pin
Jim Brooks20-Oct-07 8:57
Jim Brooks20-Oct-07 8:57 
GeneralAjax compliancy Pin
Daniele Alberto Galliano4-Oct-07 5:05
professionalDaniele Alberto Galliano4-Oct-07 5:05 
GeneralThanks Pin
azzys_lounge24-Sep-07 12:12
azzys_lounge24-Sep-07 12:12 
GeneralUnspecified Javascript Error Pin
pete9999999920-Sep-07 3:14
pete9999999920-Sep-07 3:14 
GeneralAJAX Accordion Effects on Row Expand Pin
AL268883-Sep-07 0:46
AL268883-Sep-07 0:46 
Generalusing this control Pin
smokie_30-Aug-07 22:59
smokie_30-Aug-07 22:59 
QuestionHow about an Expand/Collapse all function Pin
vonhaupt1-Aug-07 7:52
vonhaupt1-Aug-07 7:52 
AnswerRe: How about an Expand/Collapse all function Pin
Andrei Bozantan1-Aug-07 22:53
Andrei Bozantan1-Aug-07 22:53 
GeneralRe: How about an Expand/Collapse all function Pin
vonhaupt2-Aug-07 1:45
vonhaupt2-Aug-07 1:45 
QuestionThe expand button doesnt work Pin
tineo24-Jul-07 8:56
tineo24-Jul-07 8:56 
AnswerRe: The expand button doesnt work Pin
Camille9831-Jul-07 3:01
Camille9831-Jul-07 3:01 
AnswerRe: The expand button doesnt work Pin
JL. ROBERT19-Sep-07 22:47
JL. ROBERT19-Sep-07 22:47 
GeneralExpansion and column headers in extgridview Pin
Camille9820-Jun-07 6:06
Camille9820-Jun-07 6:06 
GeneralRe: Expansion and column headers in extgridview Pin
Camille9831-Jul-07 3:06
Camille9831-Jul-07 3:06 
Questionhi Pin
raffu15-Jun-07 21:34
raffu15-Jun-07 21:34 
QuestionEdit mode does not work Pin
JL. ROBERT14-Jun-07 7:39
JL. ROBERT14-Jun-07 7:39 
AnswerRe: Edit mode does not work Pin
JL. ROBERT17-Jun-07 23:54
JL. ROBERT17-Jun-07 23:54 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.