Binding Radio Buttons

I am trying to have a question in the Accordion Header and in the body 4 radio buttons to select from.  This is the source for the data I am binding. 


            Answers = new ObservableCollection<AnswerInfo>();

            Answers.Add(new AnswerInfo(1, "Question 1", "Answer 1A", DateTime.Now));

            Answers.Add(new AnswerInfo(2, "Question 1", "Answer 1B", DateTime.Now));

            Answers.Add(new AnswerInfo(3, "Question 1", "Answer 1C", DateTime.Now));

            Answers.Add(new AnswerInfo(4, "Question 1", "Answer 1D", DateTime.Now));

            Answers.Add(new AnswerInfo(5, "Question 1", "Answer 1E", DateTime.Now));

            Answers.Add(new AnswerInfo(6, "Question 2", "Answer 2A", DateTime.Now));

            Answers.Add(new AnswerInfo(7, "Question 2", "Answer 2B", DateTime.Now));

            Answers.Add(new AnswerInfo(8, "Question 2", "Answer 2C", DateTime.Now));

            Answers.Add(new AnswerInfo(9, "Question 2", "Answer 2D", DateTime.Now));

            Answers.Add(new AnswerInfo(10, "Question 2", "Answer 2E", DateTime.Now));

            Answers.Add(new AnswerInfo(11, "Question 3", "Answer 3A", DateTime.Now));

            Answers.Add(new AnswerInfo(12, "Question 3", "Answer 3B", DateTime.Now));

            Answers.Add(new AnswerInfo(13, "Question 3", "Answer 3C", DateTime.Now));

            Answers.Add(new AnswerInfo(14, "Question 3", "Answer 3D", DateTime.Now));

            Answers.Add(new AnswerInfo(15, "Question 3", "Answer 3E", DateTime.Now));


9 Replies

AK Ananthalakshmi Kannan Syncfusion Team January 10, 2024 12:21 PM UTC

Hi Joseph Cigno,

You can utilize the AccordionBindableLayout to achieve the desired functionality of having a question in the Accordion Header and four radio buttons in the body. I have also adjusted the source accordingly and attached a working sample for your reference. For further details on how to use the AccordionBindableLayout, please refer to the following guidelines: https://help.syncfusion.com/maui/accordion/bindablelayout.


Thanks and Regards,

AnanthaLakshmi K.


Attachment: AccordionBindableLayout_f4e381dd.zip


JC Joseph Cigno replied to Ananthalakshmi Kannan January 10, 2024 11:41 PM UTC

Thanks so much for the quick response.    Some of my questions may only have 2 or 3 answers.   I tried to pass null and it displayed a radio button without text.    Is there a way to make this more dynamic to work with a dynamic number of answers for questions?



AK Ananthalakshmi Kannan Syncfusion Team January 11, 2024 11:45 AM UTC

Hi Joseph Cigno,

Absolutely, you can achieve your requirement of having some questions with 2 or 3 answers by utilizing BindableLayout for RadioButton and binding the ItemsSource accordingly. I have modified the sample to meet your specifications. Kindly review it. If you require additional assistance, please feel free to ask.

Thanks and Regards,

AnanthaLakshmi K.


Attachment: AccordionBindableLayout_e17a3e90.zip


JC Joseph Cigno March 12, 2024 07:21 PM UTC

Hello Ananthalakshmi.

Thanks so much for your help.   I have my project to where I am loading the Accordion and the Radio Buttons from my database just like I want it to work.

My next step is to save the selections that he user has made.  I can't find any documentation on how to save the selections when a Submit button is pressed.

I couldn't find this thread initial to respond back here.  I created a new forum queston https://www.syncfusion.com/forums/187195/how-do-i-save-the-radio-button-selections-on-submit


If you have time to take a look and provide guidance, I would sure appreciate it.  Thanks



SY Suthi Yuvaraj Syncfusion Team March 13, 2024 03:07 PM UTC

Joseph Cigno,

We have modified the sample to get all the questions and answers related to  the selection, here we have a separate collection to set the selected items. please have a look at the sample and let us know if you have any concerns



Attachment: Sample_b0a1ad9e.zip


JC Joseph Cigno March 25, 2024 09:54 PM UTC

Thanks so very much.  That work for me.   Amazing how little code I hade to write to make this all work. Your template was key.



JS Jayashree Suresh Anand Syncfusion Team March 26, 2024 10:59 AM UTC

Hi Joseph Cigno,

Glad that your issue has been resolved, please get back to us if you need any further assistance. 

Regards,

Jayashree 



JC Joseph Cigno March 27, 2024 07:34 PM UTC

After I save the answers, I would like to clear them. The user will return to that same screen and need to answer the questions again.   The same accordion questions and answers would be available with no selections.



Thanks Joe



SY Suthi Yuvaraj Syncfusion Team March 28, 2024 01:38 PM UTC

Joseph Cigno,

We have modified the sample as per requirement, you can clear the selection and collection of selected items, Please refer the sample and let us know if you have any concerns.


Attachment: Sample_d4deb282.zip

Loader.
Up arrow icon