Browser Form and Multiple Choice Radio Button - InfoPath Dev

InfoPath Dev

Use our Google Custom Search for best site search results.

Browser Form and Multiple Choice Radio Button

Last post 09-21-2009 08:21 AM by Alec Pojidaev. 7 replies.
Page 1 of 1 (8 items)
Sort Posts: Previous Next
  • 03-20-2008 10:04 AM

    Browser Form and Multiple Choice Radio Button

    Many thanks in advance for any help.

    My environment:

    Sharepoint Server (MOSS) 2007
    SQL Database which holds a different types of questions - Text, Multiple Choice etc
    InfoPath 2007 (VSTA Enabled)
    Visual Studio 2005 (can go to 2008 if required)

    What I am trying to achieve:
    The Infopath form must be populated with the questions in the SQL database
    A user captures their answers and submits for marking
    The form is delivered through Form Services.
    No problem with Text Questions

    Multiple Choice questions are a problem. I want them to present with Radio Buttons for each questions options.

    With the rich client no problem - just use Choice group etc. But as we all know the Browser Form doesnt support choice groups.

    I have read the article about XPathNavigator and Iterator and this seems to be heading in the direction that I need, but I am struggling to get my head around exactly how this will be done.

    Once again help is much appreciated.

  • 03-20-2008 12:50 PM In reply to

    Re: Browser Form and Multiple Choice Radio Button

    Choice Groups are nice but you should be able to replicate the functionality with regular controls.

    You would use conditional formatting with the logic to hide the ones they did not choose.

    So you would display all of the choices and then depending on the value of the field from the radio button chosen it would hide the other options or at least the text.  Dropdowns might be easier to allow multiple choices than radio buttons from a UI perspective.

    If you want to attach the template or a screen shot that might help to see what you really want or need.

  • 03-25-2008 01:21 PM In reply to

    Re: Browser Form and Multiple Choice Radio Button

    Thanks for the response.

    I have a simple two table database with The First Table having questions that can be categorized as either Text or MC (Multiple Choice). The second table holds the options for the MC questions.

    I create a datasource on the infopath form using two queries - the first query selects all Questions with a type MC and the second query selects all MCOptions. When I bring the two queries onto the form the datasource provides the relationship between the two tables (everything is fine so far..) I then drag the datasource onto the form and it automatically creates a repeating table with a section inset - the repeating table repeats with each new question and the section within the repeating table shows each of the multiple choice options (still fine.....) The image below shows how the questions and multiple choice renders (looks great except for tidying up the aesthetics)

    Now when the user is answering the questions he/she should be able to select the item that is the most suitable answer using only the radio button control - "User's Choice"

    At the end of the form I will write a submit procedure that iterates through the form, selects all the answers with the radio button = true and will then write that to an answers database.

    I thought I was quite clever using the "Changed" event in infopath - but only to find that once I changed a sibling the Changed event would fire for each change - resulting in the notorious Infinite Loop (an honestly my users dont have that much time :-) ) I have also tried the conditional formatting rule using preceding-sibling and following sibling - but havent had any joy with that.

    Basically I want to achieve the functionality as per this link but in a browser enabled form.

    And again all help is really appreciated.


  • 03-25-2008 01:31 PM In reply to

    Re: Browser Form and Multiple Choice Radio Button

    How are you capturing the data?

    Do you already have web services or do you need some.

    We have all the web services to dynamically query or submit to SQL.

    Radio buttons typically only allow one response but I am guessing here you are bounding each one to its own field??? how do you prevent multiple choices?


  • 03-26-2008 08:17 AM In reply to

    Re: Browser Form and Multiple Choice Radio Button

    Fixed! (Zip file has the small Questions MDB and the Template, MDB was just for ease of working locally)

    Some general mindsifts I had to make

    1. If I am in total control (through code) of the radio buttons I only ever need to make two changes i.e. 1. set the new choice to "true", 2. find the old "true" choice and set that to "false". This applies whether I have 4 or 400 buttons in a "only one answer " scenario.

    2. I discovered that on the change event the first change is implicit i.e. 1. set new choice to true is done by virtue of clicking on the option

    So I used XPathNodeIterator to go through the rest of the options in my case grouped by ParentQuestionID excluding the current item (because I want that to stay true) find the other true option and set it to false.

    To avoid the infinite loop problem I use a field on the MainDataSource to be either 0 or 1. The value is 0 by default and I change it to 1 just before changing the selected field to false (which results in the changed event firing again)

    In the code I check to see if the value is 0 do the changes if the value is 1 do nothing but set the field back to 0. I have included the code below. It's not pretty but it works.

    public void InternalStartup()


    "/dfs:myFields/dfs:dataFields/d:MCQuestionQuery/d:MCOptionsQuery/@Selected", "MCQuestionQuery"].Changed += new XmlChangedEventHandler(MCQuestionQuery__Selected_attr_Changed);



    public void MCQuestionQuery__Selected_attr_Changed(object sender, XmlEventArgs e)



    string _checkStateField = String.Empty;

    string _qIDFilter = String.Empty;

    string _mcIDFilterToTrue = String.Empty;

    string _mcIDFilterToFalse = String.Empty;

    string _checkNode = String.Empty;

    XPathNavigator mainroot = this.MainDataSource.CreateNavigator();

    XPathNavigator root = this.DataSources["MCQuestionQuery"].CreateNavigator();

    //setup all the variables


    _qIDFilter = e.Site.SelectSingleNode("../@QuestionID").ToString(); //The specific question ID


    _mcIDFilterToTrue = e.Site.SelectSingleNode("../@MCID").ToString(); //The specific Multiple Choice ID

    _checkStateField = mainroot.SelectSingleNode("/my:myFields/my:CheckOptions/my:checkStateField", NamespaceManager).ToString(); // the check state field value



    //Check if field is zero then this is the first time the change has been activated



    if (_checkStateField == "0")


    //Find all values that match this Question ID data set

    XPathNodeIterator findTrueValues = root.Select("/dfs:myFields/dfs:dataFields/d:MCQuestionQuery/d:MCOptionsQuery/@MCID[../@QuestionID=" + _qIDFilter + "]", NamespaceManager);

    _checkNode = findTrueValues.Count.ToString();

    //MessageBox.Show("There are " + _checkNode + " values");

    while (findTrueValues.MoveNext())


    if (findTrueValues.Current.Value != _mcIDFilterToTrue)


    _mcIDFilterToFalse = findTrueValues.Current.Value;

    //MessageBox.Show("The current MCID Value is: " + _mcIDFilterToFalse);

    _checkNode = findTrueValues.Current.SelectSingleNode("/dfs:myFields/dfs:dataFields/d:MCQuestionQuery/d:MCOptionsQuery/@Selected[../@MCID =" + _mcIDFilterToFalse +"]",NamespaceManager).ToString();if (_checkNode == "True")


    mainroot.SelectSingleNode("/my:myFields/my:CheckOptions/my:checkStateField", NamespaceManager).SetValue("1");

    findTrueValues.Current.SelectSingleNode("/dfs:myFields/dfs:dataFields/d:MCQuestionQuery/d:MCOptionsQuery/@Selected[../@MCID =" + _mcIDFilterToFalse + "]", NamespaceManager).SetValue("False");


    //MessageBox.Show("This fields selected value is" + _checkNode);




    else if (_checkStateField == "1")


    "/my:myFields/my:CheckOptions/my:checkStateField", NamespaceManager).SetValue("0");





    catch (Exception ex)








    P.S. Thanks for the help Clay, not sure whether you were offering or selling the webservices, either way let me know what you were referring to. I have a dev team that are working on all of that at the moment. I dont usually dabble with code but they told me this couldnt be done...... whatever!


  • 03-26-2008 08:39 AM In reply to

    Re: Browser Form and Multiple Choice Radio Button

    Thanks for the update Darryl.

    Glad you got it figured out.

    We have a suite of installable webservices that we sell pretty inexpensively, especially compared to the cost of developing them yourself. Also they are generic so they can be reused and are not hardcoded to any one server or database.

    Send me an email if you would like to see a demonstration and discuss more.

  • 03-27-2008 10:35 AM In reply to

    Re: Browser Form and Multiple Choice Radio Button

    The saga continues.......

     A million thanks to stephane eyskens  for the response at this forum (You prevented a nervous breakdown)

    On loading the form up to sharepoint the event wouldnt trigger. So I needed to set that radio button field to post back to the server whenever it was pressed. There is an annoying infopath box that pops up with the postback but it is acceptable (for now)


Page 1 of 1 (8 items)
Copyright © 2003-2018 Qdabra Software. All rights reserved.
View our Terms of Use.