ANAT2403
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).ChildN odes %>'>
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
<asp:Repeater runat="server" ID="LeftsubMenusub" DataSource='<%# ((SiteMapNode) Container.DataItem).ChildN
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
Full Solution: -
<asp:Repeater runat="server" ID="MenuTest" DataSourceID="SiteMapDataS ource1">
<ItemTemplate>
<%# Eval("Title") %>
<hr runat="server" visible='<%# ((SiteMapNode)Container.Da taItem).Ne xtSibling! =null %>' />
</ItemTemplate>
</asp:Repeater>
<asp:Repeater runat="server" ID="MenuTest" DataSourceID="SiteMapDataS
<ItemTemplate>
<%# Eval("Title") %>
<hr runat="server" visible='<%# ((SiteMapNode)Container.Da
</ItemTemplate>
</asp:Repeater>
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
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
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Hi McExp,
Very very good. you helped me a lot.
Just another small question :
Why the following statement give me error?
(((SiteMapNode)Container.D ataItem).N extSibling .Descripti on.ToStrin g() != "more")
I want to check about properties of Nextsibling.
I've already gave you the points ofcourse.
Thanks again
Anat
Very very good. you helped me a lot.
Just another small question :
Why the following statement give me error?
(((SiteMapNode)Container.D
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)objSiteMapNod e;
if (Current.NextSibling != null)
{
return (Current.NextSibling.Descr iption != "more");
}
}
return false;
}
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)objSiteMapNod
if (Current.NextSibling != null)
{
return (Current.NextSibling.Descr
}
}
return false;
}
In your aspx page then call <%# UtilityFunctionName(Contai ner.DataIt em)%>
ASKER
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.D ataItem).N extSibling !=null) && (((SiteMapNode)Container.D ataItem).N extSibling .Descripti on.ToStrin g() != "more") %>' >|</span>
</div>
Thanks again, this problem bothered ne alot.
See you soon with my future problems.
Anat
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.D
</div>
Thanks again, this problem bothered ne alot.
See you soon with my future problems.
Anat
smn.NextSibling!= null