Search This Blog

Tuesday, February 2, 2010

Nested grid view-Dot Net

This will help you to nest grdiviews inside ASP.NET. There may be many ways to do this, but this is my way( May not be the best, let me know if you have any other ).
1. First drop a gridview in to the page, also set its DataKeyNames to your primary key
2. Add a new template column to this gridview.
3. Place another gridview inside this template column.
the code for the termplate column may look like this
’ AutoGenerateColumns=”False” CellPadding=”4″ ForeColor=”Black” GridLines=”Vertical” BackColor=”White” BorderColor=”#DEDFDE” BorderStyle=”None” BorderWidth=”1px”>
This child gridview has to show the content based on the primary of the row thats binded to main gridview.
Here in my case “pId” is the primary key. The nesting happens here

what I have done is that, I have called function “GetTrasnl” and passed the primary key to that function. This function will return a datatable. So each time a row is bound to the main gridview, the child gridview is also bound with the corresponding values.
The functions is like this
Public Function GetTrasnl(ByVal prgId As Integer) As DataTable
End Function
Please post your comments if you have any

1 comment: