Navigation menu with repeater control

F

Fabx

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
 
G

Guest

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,770
Messages
2,569,583
Members
45,075
Latest member
MakersCBDBloodSupport

Latest Threads

Top