المساعد الشخصي الرقمي

مشاهدة النسخة كاملة : Dynamic RadiobuttonList



C# Programming
10-22-2013, 12:45 AM
Hi,

I am building an entire survey dynamically. I just have a panel defined on the page, and adding controls dynamically to this panel to render my page. The survey question and answers are all stored in the database. So, i have built controls for textbox areas, checkboxlist.

I am kind of stumped on the radiobuttonlist control. It is not working on the ID part. I have defined a radiobuttonlist, and adding this list. If I define the ID outside the for loop, on submitting the code fails on "Multiple controls with the same rdb value. And if I add it inside the for loop, you are to select multiple radio buttons, which is not right.
Any ideas?? Thanks!

RadioButtonList rbL = new RadioButtonList();rbL.ID = "rdb_"; foreach (string s in eachQ[i].answer.Split(',')) {rbL.Items.Add(new ListItem(s));rbL.ID = "rdb_" + eachQ[i].answerid.ToString(); pnlQuestions.Controls.Add(rbL); }