Repeaters and SiteMapDataSources

T

Tarun Mistry

Hi guys,

im trying to do something which I feel isn't that difficult. I'm just a
little lost in the .net framework. Here goes...

I have a repeater which is using a SiteMapDataSource to bind to. I am trying
to make my own custom navigation system. All in all it works fine. I simply
create a new <asp:HyperLink> for each new entry and use the
<SeperoratorTemplate> to format how it all appears.

However, I would like to display the style of the selected page differently.
I.e. For the page the user is currently visiting, I want the HyperLink to
use a different CSS style than the rest. I can't quite figure out how todo
this. I have a feeling I need catch an event, either from the Repeater
control or the hyperlink, however im not sure what todo and what properties
to check for.

Any help in this matter would be really appreciated!

Thank you!
Taz
 
R

Rob MacFadyen

Tarun,

In the repeator ItemDataBound event you can "change things". For example:


<asp:Repeater
ID="Repeater1"
runat="server"
DataSourceID="SqlDataSource1"
OnItemDataBound="Repeater1_ItemDataBound">
<ItemTemplate>
<asp:HyperLink
ID="a"
runat="server"
CssClass="b"
NavigateUrl="~/Default.aspx">ggg</asp:HyperLink>
</ItemTemplate>
</asp:Repeater>



protected void Repeater1_ItemDataBound(
object sender, RepeaterItemEventArgs e)
{
if (e.Item.ItemType == ListItemType.Item
|| e.Item.ItemType == ListItemType.AlternatingItem)
{
HyperLink a = (HyperLink)e.Item.FindControl("a");
if (Page.ResolveUrl(a.NavigateUrl)
== Request.Url.AbsolutePath)
{
a.CssClass = "ddd";
}
}
}


Regards,

Rob
 
T

Tarun Mistry

Absolutely perfect!

I was trying todo something similar but wasnt sure how to access the
hyperlink or the sitemap.

Thanks you so much!

Kind regards
Taz
 

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,769
Messages
2,569,582
Members
45,062
Latest member
OrderKetozenseACV

Latest Threads

Top