A project was created some time ago, and sitemap was used as the navigation of the entire project during design. Third-party componentart was used for interface design, which was very convenient to use, but it is not free, because there is no money to crack, but in the process of use, there are often problems, was criticized several times on the top, also blame yourself for laziness, do not want to use js to write, later I remembered that the ajaxcontroltoolkit has an accordion that can be reduced. It is similar to componentart's navigation effect and it is not difficult to implement it. Now I want to share with you my own section.Code:
This is the aspx code.
< Ajaxtoolkit: accordion ID = "Acd1" Runat = "Server" Onitemdatabound = "Acddomainitemdatabound"
Cssclass = "Navbar" Headercssclass = "Navheader" Autosize = "Fill" Height = "400" Selectedindex = "-1" >
< Headertemplate >
<% #Eval("Title") %>
</ Headertemplate >
< Contenttemplate >
< ASP: Repeater ID = "RPT" Runat = "Server" Onitemdatabound = "Rpt_itemdatabound" >
< Itemtemplate >
< Div Class = "Divlnk" >
< ASP: hyperlink ID = "Hlnk" Cssclass = "Hlnk" Runat = "Server" Text = '<% # Eval ("title") % > 'Navigateurl =' <% #Eval("URL") %> '/>
</ Div >
</ Itemtemplate >
</ ASP: Repeater >
</ Contenttemplate >
</ Ajaxtoolkit: accordion >
Here is the CS code: Protected Void Page_load ( Object Sender, eventargs E)
{
Sitemapnode Node = Sitemap. rootnode;
This . Acd1.datasource = Node. childnodes;
Acd1.databind ();
Int I = 0 ;
Foreach (Sitemapnode No In Node. childnodes)
{
If (Sitemap. currentnode ! = Null && Sitemap. currentnode. parentnode ! = Null && Sitemap. currentnode. parentnode = No)
{
Acd1.selectedindex=I;
Break;
}
I ++ ;
}
}
Protected Void Acdshortitemdatabound ( Object Sender, ajaxcontroltoolkit. accordionitemeventargs E)
{
Repeater RPT = E. accordionitem. findcontrol ( " RPT " ) As Repeater;
If (RPT ! = Null )
{
Sitemapnode Node = E. Item As Sitemapnode;
If (Node ! = Null && Node. childnodes. Count > 0 )
{
Rpt. datasource=Node. childnodes;
Rpt. databind ();
}
}
}
Protected Void Rpt_itemdatabound ( Object Sender, repeateritemeventargs E)
{
Image img = E. Item. findcontrol ( " IMG " ) As Image;
Sitemapnode Node = E. Item. dataitem As Sitemapnode;
If (Node ! = Null )
{
String Imgurl = Node [ " IMG " ]; // Attributes added in sitemap
If (Node ! = Null && Imgurl ! = Null )
{
IMG. imageurl=Imgurl;
}
}
}
If you have learned how to bind a data control, you can understand it.
Note: This code is only used to implement second-level navigation. Many management systems have similar backend navigation.