Repeaters and SiteMapDataSources

  • Thread starter Thread starter Tarun Mistry
  • Start date Start date
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
 
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
 
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
 
Back
Top