Use ajaxcontroltoolkit: accordion for navigation bar

Source: Internet
Author: User

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.

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.