(Web menu) componentart. Menu usage

Source: Internet
Author: User

Some time ago, I wanted to use a menu function similar to the C/S architecture in a project, but I did not get it before. So Google did not find its ideal control, and the last one gave it to a friend. The effect is very good. I think a friend like me will need her to share it with you first. Here, I will introduceComponentart. MenuUsage.

Using system;
Using system. collections;
Using system. componentmodel;
Using system. Data;
Using system. drawing;
Using system. Web;
Using system. Web. sessionstate;
Using system. Web. UI;
Using system. Web. UI. webcontrols;
Using system. Web. UI. htmlcontrols;
Using system. Data. oledb;

Namespace web_menu
{
Public partial class webform2: system. Web. UI. Page
{

Private void page_load (Object sender, system. eventargs E)
{
If (! Ispostback) buildmenu ();
}

Private void buildmenu ()
{
Oledbconnection dbcon = new oledbconnection ("provider = Microsoft. Jet. oledb.4.0; Data Source =" + server. mappath ("sitemap. mdb "));
Dbcon. open ();

Oledbdataadapter adapter = new oledbdataadapter ("select * From sitemap order by nodeid", dbcon );
Dataset DS = new dataset ();
Adapter. Fill (DS );
DS. relations. Add ("noderelation", DS. Tables [0]. Columns ["nodeid"], DS. Tables [0]. Columns ["parentnodeid"]);

Foreach (datarow dbrow in DS. Tables [0]. Rows)
{
If (dbrow. isnull ("parentnodeid "))
{
Componentart. Web. UI. menuitem newitem = createitem (dbrow );
Menu1.items. Add (newitem );
Populatesubmenu (dbrow, newitem );
}
}
}

private void populatesubmenu (datarow dbrow, componentart. web. UI. menuitem item)
{< br> foreach (datarow childrow in dbrow. getchildrows ("noderelation")
{< br> componentart. web. UI. menuitem childitem = createitem (childrow);
item. items. add (childitem);
populatesubmenu (childrow, childitem);
}< BR >}

Private componentart. Web. UI. menuitem createitem (datarow dbrow)
{
Componentart. Web. UI. menuitem item = new componentart. Web. UI. menuitem ();
Item. Text = dbrow ["text"]. tostring ();
Item. navigateurl = dbrow ["navigateurl"]. tostring ();
Item. lookid = dbrow ["lookid"]. tostring ();
Item. Look. lefticonurl = dbrow ["lefticon"]. tostring ();
Item. Look. hoverlefticonurl = dbrow ["lefticonhover"]. tostring ();
Item. Look. righticonurl = dbrow ["righticon"]. tostring ();
Item. Look. hoverrighticonurl = dbrow ["righticonhover"]. tostring ();
Return item;
}
}
}
The effect is as follows:

Send it to him as needed.

Related Article

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.