Navigation menu with repeater control
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
Date:Sun, 19 Aug 2007 16:45:47 GMT
Author:
|
RE: Navigation menu with repeater control
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
"Fabx" wrote:
> 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
>
>
>
Date:Mon, 20 Aug 2007 00:58:01 -0700
Author:
|