Skip to content


GridView with Nested GridView in asp.net

Have you ever needed to nest controls within gridviews
Its actually pretty simple these days. At first i was a bit stuck but having now successfully nested many types of controls within a gridview im fairly confident its possible to nest anything, and likely down to an infinite nest tree.
So lets keep it simple
What we are going to do is have a primary gridview (grid1), with a few button controls on each row (btnexpand btnselect btndelete), a nested gridview with a couple of buttons (btnselect btndelete) and a nested control within it.
I will show you how to wire up events to handle the nested controls.
You are most likely better served by copying this code out into your favorite editor, visual studio – scite whichever your preference.

Firstly Lets look at the button controls in Grid1. The grid routine rowdatabound wires up the button control command argument to hold the ID of the record like so, this gives us a hook back to the data.

The grid rountine rowcommand is used to handle the button events.

This covers the primary grid button routines, now lets look at the nested grid buttons, how do we handle those. In the same fashion, the nested grid data would likely have been bound when we had clicked on the primary grids select button. We are only concerned at handling the nested grid button wireup and click event handler.

Simply set the “OnCommand” property of the button to our custom subroutine

Note the routine required parameters sender and e.

And that as they say is that. You have now learnt how to wireup control events through nested gridviews.

Posted in .NET, Development.


0 Responses

Stay in touch with the conversation, subscribe to the RSS feed for comments on this post.



Some HTML is OK

or, reply to this post via trackback.