Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / ASP.NET / General / August 2007

Tip: Looking for answers? Try searching our database.

Navigation menu with repeater control

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Fabx - 19 Aug 2007 17:45 GMT
Hallo,
sorry for my english.

I want to build a navigation menu with the repeat control, the items of menu
are in a table of database.

All  items of the menu have class="MenuLink", but the item of the menu of
the page that I am visiting would  to different style, as an example class=
"MenuLinkPage".

How I can make? A example?
Thanks
Ladislav Mrnka - 20 Aug 2007 08:58 GMT
Hi,
I assume you can use following example:

Define your repeater like this one:
       <asp:Repeater ID="myRepeater" runat="server"
DataSourceID="mySqlDataSource" OnItemDataBound="myRepeater_ItemDataBound">
           <ItemTemplate>
               <div runat="server" id="selector" >
                     Define your navigation here
               </div>
           </ItemTemplate>
           <SeparatorTemplate>
                 Define your separator here
           </SeparatorTemplate>
       </asp:Repeater>

To code behind file place handler for ItemDataBound event of your repeater
control.
       protected void myRepeater_ItemDataBound(object sender,
RepeaterItemEventArgs e)
   {
       // Try to find your server-side div element
       HtmlGenericControl ctl = e.Item.FindControl("selector") as
HtmlGenericControl;

       if (ctl != null)
       {
           // Here you have to place your own logic to decide if item
should be marked
           // as MenuLinkPage or not - this example always mark 3rd item is
always marked
           // Inner code simple dynamicly add class attribute with value to
div element
           if (e.Item.ItemIndex == 2)
           {
               ctl.Attributes.Add("class", "MenuLinkPage");
           }
           else
           {
               ctl.Attributes.Add("class", "MenuLink");
           }
       }
   }

As you can see I am using server-side div element and set his class
attribute based on same decision made on server.

Any way best way to make navigation is to use ASP.NET 2.0 navigation
controls. You can easily make your own SqlSiteMapProvider - MSDN Library
contains step-by-step description how to make exactly provider you need.

Regards,
Ladislav


> Hallo,
> sorry for my english.
[quoted text clipped - 8 lines]
> How I can make? A example?
> Thanks

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.