?
Solved

check end of nodes in sitemap in repeater

Posted on 2007-10-10
8
Medium Priority
?
307 Views
Last Modified: 2013-11-26
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
0
Comment
Question by:ANAT2403
  • 5
  • 3
8 Comments
 
LVL 16

Expert Comment

by:McExp
ID: 20052792
To check for the next node use: -

smn.NextSibling!= null
0
 
LVL 16

Expert Comment

by:McExp
ID: 20052862
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>
0
 

Author Comment

by:ANAT2403
ID: 20055208
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
0
Visualize your virtual and backup environments

Create well-organized and polished visualizations of your virtual and backup environments when planning VMware vSphere, Microsoft Hyper-V or Veeam deployments. It helps you to gain better visibility and valuable business insights.

 
LVL 16

Accepted Solution

by:
McExp earned 2000 total points
ID: 20055624
ok, no problem, If you change the hr for a div you will find that you still get a newline between items as div's are blocklevel items if you change the hr for a span, (as below) you should get the output I think you where searching for?

<span id="MenuSep" class="seperator" runat="server" visible='<%# ((SiteMapNode)Container.DataItem).NextSibling!=null %>' >|</span>
0
 

Author Comment

by:ANAT2403
ID: 20056701
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


0
 
LVL 16

Expert Comment

by:McExp
ID: 20056794
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;
}
0
 
LVL 16

Expert Comment

by:McExp
ID: 20056803
In your aspx page then call <%# UtilityFunctionName(Container.DataItem)%>
0
 

Author Comment

by:ANAT2403
ID: 20057143
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
0

Featured Post

Free Backup Tool for VMware and Hyper-V

Restore full virtual machine or individual guest files from 19 common file systems directly from the backup file. Schedule VM backups with PowerShell scripts. Set desired time, lean back and let the script to notify you via email upon completion.  

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Entity Framework is a powerful tool to help you interact with the DataBase but still doesn't help much when we have a Stored Procedure that returns more than one resultset. The solution takes some of out-of-the-box thinking; read on!
High user turnover can cause old/redundant user data to consume valuable space. UserResourceCleanup was developed to address this by automatically deleting user folders when the user account is deleted.
This video shows how to quickly and easily deploy an email signature for all users in Office 365 and prevent it from being added to replies and forwards. (the resulting signature is applied on the server level in Exchange Online) The email signat…
Integration Management Part 2
Suggested Courses

839 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question