nested datagrids

S

source

I need to implement a grid within a grid. How can I do this.
The reason I need to do this is because I need to show related data within a
grid from two different tables.

source
 
J

Jos

source said:
I need to implement a grid within a grid. How can I do this.
The reason I need to do this is because I need to show related data
within a grid from two different tables.

source

Put the second grid in the ItemTemplate of the first grid.
Use the OnItemBound event of the first grid to bind the second grid.
 
S

source

As a matter of fact I tried using a datagrid within the ItemTemplate, but
for some reason it did not work.
Can you tell me little more about this.
 
J

Jos

source said:
As a matter of fact I tried using a datagrid within the ItemTemplate,
but for some reason it did not work.
Can you tell me little more about this.

In the OnItemDataBound() event for the main datagrid, find the nested
datagrid like this:

Dim ndg As DataGrid = CType(e.Item.FindControl("DataGrid2",DataGrid))

Then perform databinding on it:

ndg.DataSource=whatever (probably depending on some data in e.Item)
ndg.DataBind()

Here's some examples with repeaters instead of datagrids:
http://www.c-sharpcorner.com/Code/2002/Aug/MasterDetailedDisplay.asp
http://authors.aspalliance.com/aylar/ViewArticle.aspx?ArticleID=4&PageID=1

Here's an example with a datagrid constructed on the fly:
http://www.dotnetjunkies.com/Tutorial/47792CB0-0990-4BD8-BF84-B6063C4C9BBC.dcik
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,764
Messages
2,569,567
Members
45,041
Latest member
RomeoFarnh

Latest Threads

Top