Click here to Skip to main content
15,891,372 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 832.1K   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

 
GeneralError: Element 'ExtGridView' is not a known element Pin
dayat19716-Jan-07 22:36
dayat19716-Jan-07 22:36 
GeneralRe: Error: Element 'ExtGridView' is not a known element Pin
dayat19717-Jan-07 22:08
dayat19717-Jan-07 22:08 
QuestionUnknown server tag 'cc:ExtGridView'. Pin
Oddisj28-Feb-07 22:12
Oddisj28-Feb-07 22:12 
Questiondynamic hierarchy ? Pin
shiftbit8-Dec-06 3:33
shiftbit8-Dec-06 3:33 
GeneralEditing Grids [modified] Pin
srinivas7g30-Nov-06 12:15
srinivas7g30-Nov-06 12:15 
QuestionHow to expand all records when page starts? Pin
tvtanh20-Nov-06 20:54
tvtanh20-Nov-06 20:54 
QuestionHow to allow for columns that are not visible? Pin
gnwrg20-Nov-06 11:15
gnwrg20-Nov-06 11:15 
GeneralExtGridView Pin
hutty19-Nov-06 17:02
hutty19-Nov-06 17:02 
AnswerRe: ExtGridView - TestGridControl.ascx.vb Pin
peters252120-Nov-06 6:05
peters252120-Nov-06 6:05 
AnswerRe: ExtGridView: ExtGridView.vb Pin
peters252120-Nov-06 6:09
peters252120-Nov-06 6:09 
GeneralRe: ExtGridView Pin
hutty21-Nov-06 15:23
hutty21-Nov-06 15:23 
GeneralRe: ExtGridView Pin
vikramkalsan16-Jan-07 1:48
vikramkalsan16-Jan-07 1:48 
GeneralRe: ExtGridView Pin
mjohnen17-Jun-07 11:14
mjohnen17-Jun-07 11:14 
QuestionHow to export Extgridview to Excel? Pin
peters252118-Nov-06 8:07
peters252118-Nov-06 8:07 
QuestionRe: How to export Extgridview to Excel? 2nd Pin
peters252120-Dec-06 11:38
peters252120-Dec-06 11:38 
QuestionCollapse all Pin
darin vanatta5-Nov-06 15:19
darin vanatta5-Nov-06 15:19 
GeneralCollapse all Pin
darin vanatta5-Nov-06 15:18
darin vanatta5-Nov-06 15:18 
QuestionAdjusting Column width Pin
peters252119-Oct-06 11:14
peters252119-Oct-06 11:14 
GeneralExtGridView postback problem Pin
Chris Newstead10-Oct-06 12:34
Chris Newstead10-Oct-06 12:34 
GeneralRe: ExtGridView postback problem Pin
Cesare Esposito30-Dec-06 21:09
Cesare Esposito30-Dec-06 21:09 
AnswerRe: ExtGridView postback problem Pin
JL. ROBERT8-Feb-07 3:24
JL. ROBERT8-Feb-07 3:24 
GeneralDatabase Efficiency Pin
Paul Chu29-Sep-06 13:00
Paul Chu29-Sep-06 13:00 
AnswerRe: Database Efficiency Pin
Jacatak2-Oct-06 18:29
Jacatak2-Oct-06 18:29 
GeneralMultiple ObjectDataSource Pin
Drudo29-Sep-06 4:16
Drudo29-Sep-06 4:16 
QuestionLevel Pin
kmatth00728-Sep-06 6:03
kmatth00728-Sep-06 6:03 

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.