Use ASP. NET DataGrid to display master-slave relationship data

Source: Internet
Author: User

In actual work, do you need to display data with primary and secondary structures in the DataGrid? If you are familiar with ADO. NET and SQL Server2000, we will use the example database Northwind and VB. NET provided by VS. NET to illustrate how to achieve this goal.
First, prepare the data with the primary and secondary structures to be displayed.
The following is the content of the VB. NET code file HierarchicalDataGrid. aspx. vb to be bound to HierarchicalDataGrid. aspx. VB:
Imports System. Data. SqlClient
Public Class HierarchicalDataGrid
Inherits System. Web. UI. Page
Protected WithEvents DataGrid1 As System. Web. UI. WebControls. DataGrid
# Region "Web Form Designer Generated Code"
'The following calls are required for the Web Form designer.
<System. Diagnostics. DebuggerStepThrough ()> Private Sub InitializeComponent ()
End Sub
Private Sub Page_Init (ByVal sender As System. Object, ByVal e As System. EventArgs) Handles MyBase. Init
'Codegen: This method is called by the Web Form designer.
'Do not use the code editor to change this field.
InitializeComponent ()
End Sub
# End Region
Private Sub Page_Load (ByVal sender As System. Object, ByVal e As System. EventArgs) Handles MyBase. Load
'Open the database connection
Dim OrdersConnection As New SqlConnection ("Server = (local) NetSDK; Database = northwind; Trusted_Connection = yes ")
'Get order and order details
Dim OrderAdapter As New SqlDataAdapter ("Select * from Orders; select OrderID, Products. productName, [order Details]. unitprice, [order Details]. quantity, [order Details]. discount from [order Details], Products where [Order Details]. productId = Products. productID ", OrdersConnection)
'Create and fill in the DataSet object
Dim OrderDataSet As New DataSet ()

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.