Displaying html msg once only when using a checkbox
Hi everyone,
I have a simple custom dataType Checkbox with 4 different values and would like to make a simple filtering which works well but would also like to display a message whenever the expected value is not being checked.
here is the piece of code
foreach(var item in news.Where(x=>x.GetProperty("umbracoNaviHide").Value != "1" && x.GetProperty("nhl").Value.ToString() != String.Empty).OrderByDescending(y=>y.CreateDate).Take(5)){
if(item.GetProperty("newsHotel").Value == "VPV"){ foreach(var n in item.GetProperty("nhl").Value.Split(',')){ if(n.ContainsAny("VPV")){ <li><a href="@item.Url">@item.Name</a></li>
} }
}
else{
@:No Data // here this msg should appear only once } } }
No Data message should display once only but giving me the multiple No Data taking all the nodes with checked boxes.
Ah sorry i miss type this part, they are both the same.
foreach(var item in news.Where(x=>x.GetProperty("umbracoNaviHide").Value!="1"&& x.GetProperty("nhl").Value.ToString()!=String.Empty).OrderByDescending(y=>y.CreateDate).Take(5)){
if(item.GetProperty("nhl").Value=="VPV"){ foreach(var n in item.GetProperty("nhl").Value.Split(',')){ if(n.ContainsAny("VPV")){ <li><a href="@item.Url">@item.Name</a></li> } } } else{ @:NoData// here this msg should appear only once } } }
Ok, in that case let's consider that nhl contains the value "VPV,ABC" the if will not match so we are in the else, but if nhl contains "VPV" then we are in the if but the foreach is only going to have one iteration?
So if "n.ContainsAny("VPV")" it should display the nodes. But at the moment its displaying both the @:No Data since some of the nodes does not have "VPV" checked but other checked boxes.
Sorry, I'm still slightly confused, I have simplified your code to the below:
foreach (var item in news.Where(x => x.Visible && x.HasValue("nhl")).OrderByDescending(y => y.CreateDate).Take(5))
{
if (item.GetPropertyValue("nhl") == "VPV")
{
foreach (var n in item.GetProperty("nhl").Value.Split(','))
{
if (n.ContainsAny("VPV"))
{
<li><a href="@item.Url">@item.Name</a></li>
}
}
}
else
{
@:NoData// here this msg should appear only once
}
}
Now I have one node with the value "VPV" and one node with the value "MMM" in the property alias "nhl", the output I get is what I would expect.
MNTP
NoData// here this msg should appear only once
Now I change the value of the first node to "VPV,MMM", I get
NoData// here this msg should appear only once
NoData// here this msg should appear only once
Am I right in saying that what you are after is to get the same output as my first example?
Actually, I think my IdContained function is the same as the ContainsAny method, so this should work:
foreach (var item in news.Where(x => x.Visible && x.HasValue("nhl")).OrderByDescending(y => y.CreateDate).Take(5))
{
if (item.GetPropertyValue("nhl").ContainsAny("VPV"))
{
<li><a href="@item.Url">@item.Name</a></li>
}
else
{
@:NoData// here this msg should appear only once
}
}
if(item.GetPropertyValue("nhl").ContainsAny("VPV")){ foreach(var n in item.GetProperty("nhl").Value.Split(',')){ if(n.ContainsAny("VPV")){ <li><a href="@item.Url">@altTit</a></li> } } } else{ @:NoData// here this msg should appear only once }
Am still getting all the nodes with the checked box "VPV" with No Data being displayed as well since.
Each node has a list of 4 checkboxes and on the template "VPV" only nodes with "VPV" should be displayed.
var tt = @Model.AncestorOrSelf(2).Descendants("vrn"); @if(tt.Where("nhl.Contains(\"VPV\")").Count() > 0){ foreach(var t in tt.Where("nhl.Contains(\"VPV\")")){ @t.Name <br /> }
Thanks Jeavon for you help though. Instead of displaying the message "No Data" whenever no "VPV" is checked from the list, i instead created a make a test from the list itself.
var tt = Model.AncestorOrSelf(2).Descendants("somenodes");
If any of them has "vpv" checked then the whole container is being displayed.
Displaying html msg once only when using a checkbox
Hi everyone,
I have a simple custom dataType Checkbox with 4 different values and would like to make a simple filtering which works well but would also like to display a message whenever the expected value is not being checked.
here is the piece of code
No Data message should display once only but giving me the multiple No Data taking all the nodes with checked boxes.
Any suggestion on how i might proceed on this anyone ?
what about setting a variable in the else (no data) and only showing it after the foreach - if it's set.
Not sure if this will work but will give it a shot.....
Hi Fuji,
I don't fully understand what you are trying to do, how are newsHotel and nhl related? Perhaps you could add screenshot of your content?
Jeavon
Hi Jeavon,
Ah sorry i miss type this part, they are both the same.
Ok, in that case let's consider that
nhl
contains the value "VPV,ABC" theif
will not match so we are in theelse
, but ifnhl
contains "VPV" then we are in theif
but theforeach
is only going to have one iteration?So if "n.ContainsAny("VPV")" it should display the nodes. But at the moment its displaying both the @:No Data since some of the nodes does not have "VPV" checked but other checked boxes.
Sorry, I'm still slightly confused, I have simplified your code to the below:
Now I have one node with the value "VPV" and one node with the value "MMM" in the property alias "nhl", the output I get is what I would expect.
Now I change the value of the first node to "VPV,MMM", I get
Am I right in saying that what you are after is to get the same output as my first example?
Jeavon
Youre right !
Ah ha, ok, so here is how I would do it:
If you didn't actually need to show the "No data" bit you could filter on the collection, of course you would then get 5 nodes that matched only, e.g:
Actually, I think my IdContained function is the same as the ContainsAny method, so this should work:
Hi Jeavon,
Did tried those but still not working
Am still getting all the nodes with the checked box "VPV" with No Data being displayed as well since.
Each node has a list of 4 checkboxes and on the template "VPV" only nodes with "VPV" should be displayed.
Thanks for your help on this.
Hi Fuji,
nhl is a CheckBoxList, right?
Jeavon
Yes it is. Sorry for late reply
This seems to be working right now.
Great, glad it's working for you, I am completely lost, so sorry!
Thanks Jeavon for you help though. Instead of displaying the message "No Data" whenever no "VPV" is checked from the list, i instead created a make a test from the list itself.
is working on a reply...