0

Another day, another question ;)

So, I have two custom Lists, "Attendees" and "Events". In the Events-List there's a Lookupfield "Registrations" which I want to fill programmatically on page_load. In the Events List there's a Lookupfield "Event".

First of all: I know this can be done via UI of SharePoint, and to be honest I just implemented it like this at the moment. But what I really want to achieve is the following:

In the Events-List there are two more columns, lets call them "minimal attendees" and "maximal attendees".

So now I don't just want to show the number in the "Registrations"-Column for an event, I want to show it like this: "1 of 15", ideally via SPHttpEncode in different colors (something like "orange" if registrations < min. Attendees, green if >= min. attendees and < max. attendees and red if registrations == count_related)

Now I don't know how to get the count-related value programmatically (using c#) and hope you could help :)

Best regards, Dominik

1

I suppose that you use SPLookupField which multiple property is set to true. In this case you can cast field value to the SPFieldLookupValueCollection and get its Count.

string rawvalue = item[SPBuiltInFieldId.Predecessors].ToString();
SPFieldLookupValueCollection values = new SPFieldLookupValueCollection(rawvalue);
int c = values.Count;
  • Hi Alexander and first of all thank you for your answer. To be honest, this seems to be a "bad hack" in my opinion, but I haven't found any other way yet. I'm still searching for one, though. If I won't find one the next 24h or so, I'll check your answer for it is "a" answer, I just think there have to be better ways to achieve my goal. – Dominik Dec 10 '12 at 11:10
  • @Dominik, you can also look at remark for CountRelated property of lookup field. – Alexander Dec 10 '12 at 11:21
  • I did it via int registrations = Convert.ToInt32(currEventItem["Registrations"].ToString() now ("Registrations" is the count-related lookup). It is a mess, in my opinion, but apart from the view-issue I need the int value to check if the registration limit has been reached, so... just works ;) Nonetheless you are right with your answer, so thank you. – Dominik Dec 10 '12 at 13:14
0

this is an old Topic. But a great one for my Problem!

I want to integrate the value of a look up field (Count related) into a button. What I fail to do is the Integration in the button code.

Does anybody know the solution?

Here the code for the Button:

="<input id=ViewButton onclick=""javascript:OpenPopUpPage('http://part_one_of_the_link"&Filter_by_Column&"&part_two_of_the_link');"" type=button value=""show lookup value (Count related)""/>"

if anybody has an idea - would be great!!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.