ASP.NET DataGrid to display data using the relationship between the primary and secondary author: Meng will come from: [Meng] will be the best of the world Date: 2003 at 12:00:00 on April 18
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.
Here is the content HierarchicalDataGrid.aspx to bind to the VB.NET code files HierarchicalDataGrid.aspx.vb of: Imports System.Data.SqlClientPublic Class HierarchicalDataGridInherits System.Web.UI.PageProtected WithEvents DataGrid1 As System.Web.UI.WebControls.DataGrid #Region "Web Form Designer Generated Code" 'following a call to Web Form Designer is necessary
Add the DataSet relationship OrderDataSet.Relations.Add (OrderRelation) 'is bound to the DataGrid Orders table DataGrid1.DataSource = OrderDataSet.Tables ( "Orders"). DefaultViewDataBind () End SubPrivate Sub DataGrid1_ItemDataBound (ByVal sender As Object, ByVal e System As .Web.UI.WebControls.DataGridItemEventArgs) Handles DataGrid1.ItemDataBounde.Item.Cells (0) .BackColor = System.Drawing.Color.IvoryEnd SubEnd Class in HierarchicalDataGrid.aspx, we created a template for the column DataGrid1, and put another DataGrid Embedded into this template column, the parent-level DataGrid is used to display the main record, such as: orders. The child level DataGrid is used to display details, such as the details of the order. We have dynamically specified data sources for sub-DataGrid: DataSource = '<% # ctype (container.DataItem, DATAROWVIEW) .CreateChildview ("ORDERRELATION")%>> The above sentence is to implement the key to displaying the main item 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.
Here is the code ASPX page, we want to display, HierarchicalDataGrid.aspx: <% @ Page Language = "vb" AutoEventWireup = "false" Codebehind = "HierarchicalDataGrid.aspx.vb" Inherits = "HierarchicalDataGrid.HierarchicalDataGrid"%> <% @ Import namespace = "system.data" - // w3c // DTD HTML 4.0 Transitional // en ">