/// <summary>
 /// Retrieves the given answer item from the control collection
 /// </summary>
 private static AnswerItem GetAnswerItem(AnswerItemCollection answers, int answerId)
 {
     foreach (AnswerItem item in answers)
     {
         if (item.AnswerId == answerId)
         {
             return item;
         }
     }
     return null;
 }
 /// <summary>
 /// Subscribe the answer items which require it to the correct
 /// answer publisher controls defined as defined by the Subscriber collection
 /// </summary>
 public static void ActivateAnswerConnections(AnswerConnectionsCollection answerConnections, AnswerItemCollection answers)
 {
     foreach (AnswerConnection connection in answerConnections)
     {
         IAnswerSubscriber answerItem = GetAnswerItem(answers, connection.SubscriberId) as IAnswerSubscriber;
         if (answerItem != null)
         {
             AnswerItem item2 = GetAnswerItem(answers, connection.PublisherId);
             if ((item2 != null) && (item2 is IAnswerPublisher))
             {
                 item2.AnswerPublished += new AnswerPublisherEventHandler(answerItem.ProcessPublishedAnswers);
                 item2.AnswerPublisherCreated += new AnswerPublisherEventHandler(answerItem.PublisherCreation);
             }
         }
     }
 }
 /// <summary>
 /// Subsribe the answer items which require it to the correct
 /// answer publisher controls
 /// </summary>
 public static void BindSubscribersToPublishers(AnswerItemCollection answers)
 {
     foreach (AnswerItem item in answers)
     {
         IAnswerSubscriber subscriber = item as IAnswerSubscriber;
         if (subscriber != null)
         {
             foreach (AnswerData.AnswersRow row in new Answers().GetSubscriptionList(item.AnswerId).Answers.Rows)
             {
                 AnswerItem answerItem = GetAnswerItem(answers, row.AnswerId);
                 if (answerItem != null)
                 {
                     answerItem.AnswerPublished += new AnswerPublisherEventHandler(subscriber.ProcessPublishedAnswers);
                     answerItem.AnswerPublisherCreated += new AnswerPublisherEventHandler(subscriber.PublisherCreation);
                 }
             }
             continue;
         }
     }
 }
 /// <summary>
 /// Parse an AnswerDataCollection, converts the data and
 /// returns an AnswerItemCollection filled with the correct 
 /// child controls
 /// </summary>
 /// <param name="answers">A collection of answerdata entities</param>
 /// <param name="defaultSelectionMode">The default selection mode for the 
 /// item (Radio, checkbox etc...)</param>
 /// <param name="parentcontrolUniqueID">
 /// Unique ID required to identify global groups 
 /// like radiobutton groups
 /// </param>
 /// <param name="showAnswerText">
 /// Assigns the text to the answeritem control ?
 /// </param>
 /// <param name="voterAnswersState">
 /// Current state of answers, used for piping. If not available
 /// leave it to null 
 /// </param>
 /// <param name="enableDefaults">
 /// Does the answer set the user default values of fields to the answer web controls
 /// </param>
 /// <returns>A collection of answeritem web controls</returns>
 public static AnswerItemCollection CreateAnswerItemCollection(AnswerData answers, QuestionItem question, Section section, AnswerSelectionMode defaultSelectionMode, Style answerStyle, ControlRenderMode renderMode, string languageCode, string parentControlUniqueID, bool showAnswerText, VoterAnswersData.VotersAnswersDataTable voterAnswersState, bool enableDefaults)
 {
     AnswerItemCollection items = new AnswerItemCollection();
     foreach (AnswerData.AnswersRow row in answers.Answers.Rows)
     {
         items.Add(Create(row, question, section, defaultSelectionMode, answerStyle, renderMode, languageCode, parentControlUniqueID, showAnswerText, voterAnswersState, enableDefaults));
     }
     return items;
 }