PDA

View Full Version : [CLOSED] Read Value from Dynamically Generated Radio Group



ljankowski
Oct 11, 2013, 3:26 PM
I have a dynamically generated form working off of questions in a database. Here's how the radio group/options are generated.



if (question.QuestionType.TypeName == "radio"){
ext.RadioGroup RadioGroup = new ext.RadioGroup()
{
ID = "q" + question.FormQuestionID.ToString(),
FieldLabel = question.QuestionText,
LabelAlign = ext.LabelAlign.Top,
MaxWidth = 400,
};
List<QuestionOption> Options = (from o in MyConn.QuestionOption
where question.FormQuestionID == o.FormQuestionId
select o).ToList();
foreach (QuestionOption o in Options)
{
RadioGroup.Items.Add(new ext.Radio()
{
ID= "o" + o.QuestionOptionId.ToString(),
BoxLabel = o.OptionName,
Value = o.QuestionOptionId.ToString(),
MaxWidth = 50,
Padding = 5,
Margin = 5
});
}


MyContainer.Items.Add(RadioGroup);
}

After the form is filled out, in PageLoad I regenerate the form, and then the Click Handler for the Submit Button fires. Here's how I iterate through the response if it's a radio button.


if (question.TypeName == "radio")
{
FormAnswer Answer = new FormAnswer{
FormQuestionID = question.FormQuestionID,
Answer = Request["q" + question.FormQuestionID]
};
MyConn.FormAnswer.Add(Answer);
}


For text, textarea, datepicker, and dropdown fields, the responses are captured and saved to the database properly. For the radio buttons, the Request["q" + question.FormQuestionID] is null.

I also tried


ext.X.GetCmp<ext.RadioGroup>("q" + question.FormQuestionID).CheckedItems[0].Value.ToString()
and receive an Invalid cast exception on CheckedItems

ljankowski
Oct 11, 2013, 4:24 PM
I got the radio values by following

http://forums.ext.net/showthread.php?21446-CLOSED-radiogroup-CheckItems-is-always-0-in-dynamically-created-radiogroup

Is the same true for CheckBoxes?

Daniil
Oct 11, 2013, 4:39 PM
Hi @ljankowski,


Is the same true for CheckBoxes?

Yes, I think it is the same with CheckboxGroup.