Link to home
Start Free TrialLog in
Avatar of ANAT2403
ANAT2403Flag for Israel

asked on

check end of nodes in sitemap in repeater

IN ASP.NET with C# I have the following declaration:
 <asp:Repeater runat="server" ID="LeftsubMenusub"     DataSource='<%# ((SiteMapNode) Container.DataItem).ChildNodes %>'>

I want in this section in the source code to check if the current node has a next node. If yes I will print a seperator and if not I will not.
How do I write the check in <% %>
Anat
Avatar of McExp
McExp
Flag of United Kingdom of Great Britain and Northern Ireland image

To check for the next node use: -

smn.NextSibling!= null
Full Solution: -

<asp:Repeater runat="server" ID="MenuTest" DataSourceID="SiteMapDataSource1">
<ItemTemplate>
<%# Eval("Title") %>
<hr runat="server" visible='<%# ((SiteMapNode)Container.DataItem).NextSibling!=null %>' />
</ItemTemplate>
</asp:Repeater>
Avatar of ANAT2403

ASKER

Hi,
You solution seem to be great but I don't manage to implement it and I am sure it is something small you will manage to help:
I want the following line
<div class="separator">|</div>
to set as visible or not or to enter as an if statement.
what tag should I use instead of your <hr>?
Thankyou
anat
ASKER CERTIFIED SOLUTION
Avatar of McExp
McExp
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Hi McExp,
Very very good. you helped me a lot.
Just another small question :
Why the following statement give me error?
(((SiteMapNode)Container.DataItem).NextSibling.Description.ToString() != "more")
I want to check about properties of Nextsibling.
 I've already gave you the points ofcourse.
Thanks again
Anat


I would guess that this is causing an error when you get to a node without a NextSibling. when the code reaches a NextSibling of null it will then try and test null.Description.ToString().
 
Which would fail with an object refrence not set instance of object error?

What I would do in this case is create a helper function in your codeBehind (which may not comple as I have just typed it directly to this form)

function bool UtlityFunctionName(object objSiteMapNode)
{
  if (objSiteMapNode.GetType() == typeof(SiteMapNode)
    {
      SiteMapNode current = (SiteMapNode)objSiteMapNode;
      if (Current.NextSibling != null)
        {
          return (Current.NextSibling.Description != "more");
        }
    }
    return false;
}
In your aspx page then call <%# UtilityFunctionName(Container.DataItem)%>
Hi McExp,
Ofcourse you are absolutely right.
I had to put 2 conditions in my code so I just changed the order without using the code brhind.
This is the final solution:

<div class="separator">
<span id="MenuSep"  runat="server" visible='<%# (((SiteMapNode)Container.DataItem).NextSibling!=null)  &&  (((SiteMapNode)Container.DataItem).NextSibling.Description.ToString() != "more")  %>' >|</span>
</div>

Thanks again, this problem bothered ne alot.
See you soon with my future problems.
Anat