You can place the ASP.Net GridView control nested inside the ItemTemplate of Template Field Column of another ASP.Net GridView control to display the related data. VB.Net code can be used to bind the data items to the parent GridView control and further to the nested gridview control using VB.Net for each loop. Nested GridView controls enable you to retrieve and display the parent items as well as their related child items from the SQL Database very easily.
GridView Properties Used
The DataKeyNames property of the ASP.Net GridView control accepts the name of the unique key of the database table used to bind the records to it. For example in this sample we have the categories table of Northwind SQL database to display the categories and we have specified the categoryId data fields to the DatKeyNames property of the GridView control. The DataKeys Array Collection type property enables you to retrieve the DataKey values associated to each row item of GridView. For example in this sample the DataKey array collection will return the categoryid for the associated row item of the GridView control.
VB.Net Method Used
1. FindControl method
The VB.Net FindControl method accepts the ID of the web server control that you want to find and access which is placed inside the GridView control. In this sample we have used the VB.Net FindControl method to access the nested GridView control.
Try the sample below to understand the functionality of nested GridView control created using VB.Net code in ASP.net: