Click here to Skip to main content
15,868,016 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 827.6K   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

 
GeneralHaving an issue running the demo Pin
zsim13-Dec-05 6:28
zsim13-Dec-05 6:28 
GeneralNice job Pin
Fabian Lopez12-Dec-05 8:24
Fabian Lopez12-Dec-05 8:24 
GeneralExcellent Pin
QC107-Dec-05 22:37
QC107-Dec-05 22:37 
GeneralRe: Excellent Pin
Andrei Bozantan8-Dec-05 5:52
Andrei Bozantan8-Dec-05 5:52 
QuestionCan you elaborate on the .xsd and .xss files? Pin
hellohoa7-Dec-05 8:02
hellohoa7-Dec-05 8:02 
AnswerRe: Can you elaborate on the .xsd and .xss files? Pin
Andrei Bozantan7-Dec-05 20:58
Andrei Bozantan7-Dec-05 20:58 
GeneralPlese Please!!! Pin
Sharon B.S4-Dec-05 23:26
Sharon B.S4-Dec-05 23:26 
GeneralRe: Plese Please!!! Pin
Andrei Bozantan5-Dec-05 2:05
Andrei Bozantan5-Dec-05 2:05 
I added a sample project for Visual Studio 2003.
GeneralRe: Plese Please!!! Pin
Sharon B.S5-Dec-05 2:19
Sharon B.S5-Dec-05 2:19 
GeneralRe: Plese Please!!! Pin
Andrei Bozantan5-Dec-05 2:46
Andrei Bozantan5-Dec-05 2:46 
GeneralRe: Plese Please!!! Pin
Sharon B.S5-Dec-05 3:48
Sharon B.S5-Dec-05 3:48 
QuestionV1.1? Pin
MrHankg28-Nov-05 8:17
MrHankg28-Nov-05 8:17 
AnswerRe: V1.1? Pin
Andrei Bozantan28-Nov-05 11:03
Andrei Bozantan28-Nov-05 11:03 
QuestionHelp Pin
cheepau27-Nov-05 22:34
cheepau27-Nov-05 22:34 
AnswerRe: Help Pin
Andrei Bozantan28-Nov-05 0:17
Andrei Bozantan28-Nov-05 0:17 
QuestionRe: Help Pin
cheepau28-Nov-05 13:52
cheepau28-Nov-05 13:52 
GeneralCool - thank you. Pin
rlodina24-Nov-05 7:03
rlodina24-Nov-05 7:03 
GeneralCool Pin
leppie21-Nov-05 20:52
leppie21-Nov-05 20:52 
Generalnice job. Pin
margiex21-Nov-05 14:30
margiex21-Nov-05 14:30 

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.