Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: ASP.NET C#4.0
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
 
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 28-Mar-13 21:06pm
NaniCh709

1 solution

Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

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).
 
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)
  Permalink  
Comments
NaniCh at 29-Mar-13 7:41am
   
can you please send me sample code...?
V. at 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)



Advertise | Privacy | Mobile
Web03 | 2.8.1411022.1 | Last Updated 29 Mar 2013
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100