Strings in c# are immutable. When in your code you do strgroupids.TrimEnd(',');
or strgroupids.TrimEnd(new char[] { ',' });
the strgroupids
string is not modified.
You need to do something like strgroupids = strgroupids.TrimEnd(',');
instead.
To quote from here:
Strings are immutable--the contents of a string object cannot be changed after the object is created, although the syntax makes it appear as if you can do this. For example, when you write this code, the compiler actually creates a new string object to hold the new sequence of characters, and that new object is assigned to b. The string "h" is then eligible for garbage collection.