GridView multi-layer nesting and folding and expansion (modified for its own use) _ Practical skills

Source: Internet
Author: User
Tags unique id
Insus.net in the near period of time at the request of friends, write a GridView multi-layer nesting and folding and expansion. This feature of the GridView multi-layer nesting is not a problem, because has done an infinite number of times, but the folding and expansion of the function, but spent a lot of time (online looking for information), although found information can be referred to, or understand it, and modify the appropriate procedures for their use. The effect is as follows:

Multiple pages in a site, so Insus.net writes it on a user-defined control ascx.
Copy Code code as follows:

Insusmenu.ascx

<%@ control language= "VB" autoeventwireup= "false" codefile= "InsusMenu.ascx.vb" inherits= "Ascxcontrols_insusmenu" %>

<!--the javascript portion of the collapsed and expanded-->
<script type= "Text/javascript" language= "JavaScript" >
function Showhidde (SID, Evt) {
EVT = EVT | | window.event;
var target = Evt.target | | 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/+.gif": "Image/-.gif";
}
</script>
<!--first floor-->
<asp:gridview id= "gridviewyear" runat= "Server" width= "100%" autogeneratecolumns= "False"
Onrowdatabound= "Gridviewyear_rowdatabound" showheader= "false" borderwidth= "0" >
<Columns>
<asp:TemplateField>
<itemstyle borderwidth= "0" height= "/>"
<ItemTemplate>

<!--under this binding eval ("year"), is to get 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/+.gif "onclick=" Showhidde (' <% #Eval ("Year ")%> ', event)"/>

<!--The following binding, is the first layer of text displayed-->
<%# Eval ("year") & "%>"
<div id= ' div<%# Eval ("year")%> ' style= ' display:none; >

<!--second floor-->
<asp:gridview id= "Gridviewmonth" runat= "Server" onrowdatabound= "Gridviewmonth_rowdatabound" Width= "100%" Autogeneratecolumns= "false" Showheader= "false" borderwidth= "0" >
<Columns>
<asp:TemplateField>
<itemstyle borderwidth= "0" height= "/>"
<ItemTemplate>
<!--This part of the explanation can be referred to above. -->
' style= ' border:0px; padding-left:20px "src=" Image/+.gif "onclick=" Showhidde (' <% #Eval ("Month")%> ', event) '/>
<%# Eval ("Month") & "Month"%>
<div id= ' div<%# Eval ("Month")%> ' style= ' Display:none; " >

<!--third floor-->
<asp:gridview id= "Gridviewvideofile" runat= "Server" width= "100%" autogeneratecolumns= "False"
Showheader= "False" borderwidth= "0" >
<Columns>
<asp:TemplateField>
<itemstyle borderwidth= "0" height= "/>"
<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 Code code as follows:

InsusMenu.ascx.vb

Imports System.Data
Imports insus.net

Partial Class Ascxcontrols_insusmenu
Inherits System.Web.UI.UserControl

' Declaring 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 ()
' Get data from the database, bind to the GridView at the first level
Me.GridViewYear.DataSource = Objvideolibrary.getyear ()
Me.GridViewYear.DataBind ()
End Sub

' Data binding on the second level of 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 If
End Sub

' Data binding on the third level of 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 If
End Sub
End Class

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.