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.
Copy codeThe Code is as follows:
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>
<! -- 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, you can bind the field name of the primary key. -->
'style = "border: 0px; "src =" Image/images .gif "onclick =" ShowHidde ('<% # Eval ("Year") %>', event) "/>
<! -- The following binding is the text displayed at the first layer -->
<% # Eval ("Year") & "Year" %>
<Div id = 'div <% # Eval ("Year") %> 'style = "display: none;">
<! -- Layer 2 -->
<Asp: GridView ID = "GridViewMonth" runat = "server" OnRowDataBound = "GridViewMonth_RowDataBound" Width = "100%" AutoGenerateColumns = "False" ShowHeader = "False" BorderWidth = "0">
<Columns>
<Asp: TemplateField>
<ItemStyle BorderWidth = "0" Height = "25"/>
<ItemTemplate>
<! -- For the explanation of this part, refer to the above. -->
'style = "border: 0px; padding-left: 20px; "src =" Image/images .gif "onclick =" ShowHidde ('<% # Eval ("Month") %>', event) "/>
<% # Eval ("Month") & "Month" %>
<Div id = 'div <% # Eval ("Month") %> 'style = "display: none;">
<! -- Layer 3 -->
<Asp: GridView ID = "GridViewVideoFile" runat = "server" Width = "100%" AutoGenerateColumns = "False"
ShowHeader = "False" BorderWidth = "0">
<Columns>
<Asp: TemplateField>
<ItemStyle BorderWidth = "0" Height = "25"/>
<ItemTemplate>
<asp: HyperLink ID =" HyperLinkPlayer "runat =" server "NavigateUrl = '<% #"~ /VideoPlayer. aspx? Videokey = "& Eval (" VideoLibrary_nbr ") %> 'text = '<% # Eval (" OldFileName "). substring (0, Eval ("OldFileName "). lastIndexOf (". ") %> 'target =" _ blank "> </asp: HyperLink>
</ItemTemplate>
</Asp: TemplateField>
</Columns>
</Asp: GridView>
</Div>
</ItemTemplate>
</Asp: TemplateField>
</Columns>
</Asp: GridView>
</Div>
</ItemTemplate>
</Asp: TemplateField>
</Columns>
</Asp: GridView>
Copy codeThe Code is as follows:
InsusMenu. ascx. vb
Imports System. Data
Imports Insus. NET
Partial Class AscxControls_InsusMenu
Inherits System. Web. UI. UserControl
'Advertise an 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 ()
'Obtain data from the database and bind it to the first-level GridView
Me. GridViewYear. DataSource = objVideoLibrary. GetYear ()
Me. GridViewYear. DataBind ()
End Sub
'Data is bound to the GridView on the second layer.
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 If
End Sub
'Data is bound to the GridView on the third layer.
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 If
End Sub
End Class