Do you have any data to show a primary structure in DataGrid in actual work? If you are familiar with ADO.NET and SQL Server 2000, we will give this goal with the sample database northwind and vb.net that comes with VS.NET comes with VS.NET.
First, let's first prepare data to be displayed.
Below is the contents of the VB.NET code file hierarchicalDataGrid.aspx.vb to hierarchicalDataGrid.aspx:
Imports System.Data.SqlClientPublic Class HierarchicalDataGridInherits System.Web.UI.PageProtected WithEvents DataGrid1 As System.Web.UI.WebControls.DataGrid # Region "Web Form Designer Generated Code" 'The following call to the Web Form Designer is a must
) .DefaultViewDataBind () End SubPrivate Sub DataGrid1_ItemDataBound (ByVal sender As Object, ByVal e As System.Web.UI.WebControls.DataGridItemEventArgs) Handles DataGrid1.ItemDataBounde.Item.Cells (0) .BackColor = System.Drawing.Color.IvoryEnd SubEnd Class In HierarchicalDataGrid.aspx, we build template columns for DataGrid1 and embed another DataGrid into this template column, and parent-level DataGrid is used to display master records, such as: Order. The child level DataGrid is used to display details, such as the details of the order. We use this to dynamically specify data sources for sub-DataGrid:
DataSource = '<% # ctype (container.DataItem, DataRowView) .createchildview ("ORDERRELATION")%>>>
The above sentence is to achieve the key to displaying the main secondary data. Depending on the current parent-level record, DataRowView.createChildView uses the name of the relationship created in front as a parameter to obtain sub-record and bind it to the sub-DataGrid.
Below is the code of the ASPX page we have to display, hierarchicalDataGrid.aspx:
<% @ Page Language = "vb" AutoEventWireup = "false" Codebehind = "HierarchicalDataGrid.aspx.vb" Inherits = "HierarchicalDataGrid.HierarchicalDataGrid"%> <% @ Import namespace = "System.Data"%>