I'm a bit lost here working with an asp:CheckboxList. The list displays several categories that is related (using the relationship api) to a document. The member is then able to edit the document and change the selected values(categories) and save the document.
So, in technical terms when a member clicks the 'Save' button I need to:
Check if the selected item/node is already related to the document, if not: make a new relation
For every item/node that's not selected, check to see if there is a relation to the document, if there is: delete it.
I almost wrote it in pseudo right there and it should be fairly straight forward in my eyes. I have the following code:
Relation.MakeNew(nodeId, relatedNode.Id, spot2Category, nodeId + " is related to " + relatedNode.Name);
}
}
else
{
foreach (Relation r in spot2CategoryRelations)
{
if (Relation.IsRelated(nodeId, relatedNode.Id))
{
r.Delete();
}
}
}
}
nodeId is the id of the document you are editing. I'm databinding my CheckboxList in the Page_Load event in a !Page.IsPostBack. The problem with the above code is:
It doesn't do anything about the relations. It's not creating one or deleting existent relations.
I don't like the nested loops! Is there a more elegant way of doing this, instead of my ninja-code? ;)
10 hours and I stil haven't found a solution to this problem :( just even more confused really. So, if anyone out there has got just the smallest hint on this, I will be more than happy! :)
foreach (ListItem l in cbMemberTypes.Items)
{
if (l.Selected)
{
Node relatedNode = ca.SingleOrDefault(x => x.Name.Equals(l.Text));
if (!Relation.IsRelated(relatedNode.Id, nodeId))
{
Relation.MakeNew(relatedNode.Id, nodeId, spot2Category, nodeId + " is related to " + relatedNode.Name);
}
}
}
Which is way more elegant and simple than my previous ninja-code! Thanks a lot Rick :) honestly don't know why I didn't think of the lambda-thingy..
Confused about ASP.NET CheckboxList
Hi 'bracos!
I'm a bit lost here working with an asp:CheckboxList. The list displays several categories that is related (using the relationship api) to a document. The member is then able to edit the document and change the selected values(categories) and save the document.
So, in technical terms when a member clicks the 'Save' button I need to:
10 hours and I stil haven't found a solution to this problem :( just even more confused really. So, if anyone out there has got just the smallest hint on this, I will be more than happy! :)
Thanks!
Bo
I can't tell why it isn't working but if you want to simplify your code, you should be able to replace the entire 'while' block with this (untested):
Beautiful! :)
Solved it by doing this:
Which is way more elegant and simple than my previous ninja-code! Thanks a lot Rick :) honestly don't know why I didn't think of the lambda-thingy..
is working on a reply...