Click here to Skip to main content
15,892,927 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi experts
i did adding radio buttons dynamically in a table. then how can i get checked radio button values in that table

here i post my ocde

C#
int j = 0;
            int k = 0;
            string l = "0";
            foreach (var q in MyList)
            {
                if (q.OptionGroup == "Radio Buttons")
                {
                        TableRow tr = new TableRow();
                        tr.Font.Bold = true;
                        TableCell tc = new TableCell();
                        Label lblquestion = new Label();
                        tc.Height = 10;
                        lblquestion.Text = q.Name;
                        tc.Controls.Add(lblquestion);
                        tr.Controls.Add(tc);
                        for (int i = 0; i < Mylist.Length; i++)
                        {
                            TableRow tr1 = new TableRow();
                            TableCell cl = new TableCell();
                            TableCell cl2 = new TableCell();
                            Label txt = new Label();
                            txt.Text = AnswerName;
                            txt.ID = "Lableanswer" + k;
                            cl.Height = 10;
                            cl2.Height = 10;
                            RadioButton raid = new RadioButton();
                            raid.ID = "raid" + j;
                            raid.GroupName = l;
                            cl.Controls.Add(txt);
                            cl2.Controls.Add(raid);
                            tr.Controls.Add(cl);
                            tr.Controls.Add(cl2);
                           
                            j++;
                            k++;
                            table1.Controls.Add(tr1);
                        }
                        table1.Controls.Add(tr);

                    }
                    l = l + 1;
                }
}


here we have multiple radiobutton in each row.. how can i get checked radio button values in each row..

please help me..

Thanks in advance..
Posted

1 solution

Basically there are two ways:

1.
Loop the table, check the cell that contains the radiobutton to see if it is checked or not.

2.
Add an event handler to the radiobutton on creation (the same handler for each radiobutton).

C#
raid.Clicked += ... 


When clicked, the sender object can be casted to a RadioButton object ("unboxed") and the value updated in a list of some kind. (eg. Dictionary<string,> where string is the button name)
 
Share this answer
 
Comments
NaniCh 29-Mar-13 7:41am    
can you please send me sample code...?
V. 29-Mar-13 8:10am    
You should be able to deduce the code from the tips I gave you. I would send code if I had a sample lying around, but I would have to write one from scratch myself.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900