I am creating a table containing the grades pupils received for certain skills. I have created a set of buttons, each representing a different skill, and created a set of radiobuttons alongside each skill button. For each skill one and only one radiobutton is checked to show the grade the pupil received. I.e. if the pupil received a "1" then the first radiobutton would be selected but if the pupil received a "5" then the fifth radiobutton would be selected. Here's the essentials of my code:
Code:
// Create a set of buttons
for (int i = 0; i < skillList.Length; i++)
{
btnSkill = new Button();
btnSkill.ID = skillList[i].ID; // This comes from the webservice
// For every btnSkill add a number of radiobuttons
for (int x = 0; x < gradeList.Length; x++)
{
int grade = x + 1;
rbtnSkill = new RadioButton();
rbtnSkill.ID = skillList[i].Name + "_" + grade;
rbtnSkill.Checked = false;
rbtnSkill.AutoPostBack = true;
rbtnSkill.CheckedChanged += new EventHandler(rbtnSkill_CheckedChanged);
}
}
On loading the page I would like the corresponding radiobuttons to be checked (this information should come from the webservice). I am however only able to check one radiobutton instead of all of them since rbtnSkill only refers to the last created/selected radiobutton! How do I overcome this problem?
Code:
// Only checks ONE rbtn
protected void GetEvaluationData()
{
// For each rbtn in the list, i.e. all 10
for (int i = 0; i < skillList.Length; i++)
{
// Split rbtn ID to return a string with the rbtn's skill name and another string containing the rbtns grade
SplitRbtnID(rbtnSkill.ID);
// Loop through each group of rbtns
// If rbtnID in question has this groupname
if (rbtnIDList[0] == skillList[i].Name)
{
// Loop through whole loop to see if equals current position in grade group
for(int a = 0; a < gradeList.Length; a++)
{
// If equals current eNumGrade
if(rbtnIDList[1] == gradesList[a])
{
// Check rbtn
rbtnSkill.Checked = true;
}
}
}
}
}