GridView multi-layer nesting, collapse and expansion, and gridview multi-layer nesting
Insus. NET should be a friend's request in the near future to write a GridView multi-layer nesting, folding and expansion. There is no problem with the multi-layer nesting of the GridView function because it has already been used for an unlimited number of times, but the function of folding and expansion takes a lot of time (searching for information on the internet). Although you can find the information for reference, understand it and modify it to suit your program. The effect is as follows:
The website uses multiple pages, so Insus. NET writes it on a user-defined control ASCX.
InsusMenu. ascx <% @ Control Language = "VB" AutoEventWireup = "false" CodeFile = "InsusMenu. ascx. vb" Inherits = "AscxControls_InsusMenu" %> <! -- Collapse and expand the Javascript section --> <script type = "text/javascript" language = "javascript"> function ShowHidde (sid, evt) {evt = evt | window. event; var target = evt.tar get | evt. srcElement; var objDiv = document. getElementById ("div" + sid); objDiv. style. display = objDiv. style. display = "none "? "Block": "none"; target. title = objDiv. style. display = "none "? "Show": "Hide"; var imgid = 'img '+ sid; document. getElementById (imgid). src = objDiv. style. display = "none "? "Image/developer.gif": "Image/-.gif" ;}</script> <! -- The first layer --> <asp: gridView ID = "GridViewYear" runat = "server" Width = "100%" AutoGenerateColumns = "False" OnRowDataBound = "GridViewYear_RowDataBound" ShowHeader = "false" BorderWidth = "0"> <Columns> <asp: templateField> <ItemStyle BorderWidth = "0" Height = "25"/> <ItemTemplate> <! -- Bind Eval ("Year") to obtain a unique ID. If your record has a primary key, the field name that can be bound to the primary key --> '> InsusMenu. ascx. vbImports System. dataImports Insus. NETPartial Class AscxControls_InsusMenu Inherits System. web. UI. userControl 'declare instance Dim objVideoLibrary As New VideoLibrary () Protected Sub Page_Load (sender As Object, e As EventArgs) Handles Me. load If Not IsPostBack Then Data_Binding () End If End Sub Private Sub Data_Binding () 'gets data from the database and binds it to the GridView Me at the first layer. gridViewYear. dataSource = objVideoLibrary. getYear () Me. gridViewYear. dataBind () End Sub 'data is bound to the GridView Protected Sub GridViewYear_RowDataBound (sender As Object, e As GridViewRowEventArgs) Dim dvr As DataRowView = DirectCast (e. row. dataItem, DataRowView) If e. row. rowType = DataControlRowType. dataRow Then If e. row. findControl ("GridViewMonth") IsNot Nothing Then Dim Gv As GridView = DirectCast (e. row. findControl ("GridViewMonth"), GridView) objVideoLibrary. year = ConvertData. toSmallInt (dvr ("Year") Gv. dataSource = objVideoLibrary. getMonthByYear () Gv. dataBind () End If End Sub 'data is bound to the GridView Protected Sub GridViewMonth_RowDataBound (sender As Object, e As GridViewRowEventArgs) Dim dvr As DataRowView = DirectCast (e. row. dataItem, DataRowView) If e. row. rowType = DataControlRowType. dataRow Then If e. row. findControl ("GridViewVideoFile") IsNot Nothing Then Dim Gv As GridView = DirectCast (e. row. findControl ("GridViewVideoFile"), GridView) objVideoLibrary. year = ConvertData. toSmallInt (dvr ("Year") objVideoLibrary. month = ConvertData. toTinyInt (dvr ("Month") Gv. dataSource = objVideoLibrary. getByYearAndMonth () Gv. dataBind () End If End SubEnd Class