Click here to Skip to main content
15,298,916 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Iwant to do survey.
there is an placeholder(place holder has dynamic created label and dynamic created radiobuttonlist) inside survey usercontrol.I checked how many question are there.

usercontrol-->placeholder-->label and radiobuttonlist(created dynamicly because we dont know how many question are there)
there is no problem up to here Iam getting questions and create label and radiobuttonlist

MySqlCommand command = new MySqlCommand("xxxxx", conn);
command.CommandType = System.Data.CommandType.StoredProcedure;
command.Parameters.Add("@surveyno", MySqlDbType.VarChar).Value = yyy;


MySqlDataAdapter dAdapter = new MySqlDataAdapter(command);
DataSet dset = new DataSet();
MySqlDataReader reader = command.ExecuteReader();

while (reader.Read())
Label myLabel = new Label();
RadioButtonList rdr = new RadioButtonList();
rdr.Items.Add(new ListItem("Yes", "1"));
rdr.Items.Add(new ListItem("No", "2"));

myLabel.Text = reader["sorular"].ToString();
PlaceHolder1.Controls.Add(new LiteralControl("


but I select answers question one yes question two no etc. click save button it dont find radiobuttonlist in the placeholder.
Code like this
foreach (Control ctrl in this.PlaceHolder1.Controls)

   if (ctrl is RadioButtonList)

                        string soruid = ((RadioButtonList)ctrl).ID;
                         string puan = ((RadioButtonList)ctrl).SelectedValue;
                         if (puan == null || puan == "")
                           puan = "0";



1 solution

Firstly give the radiobuttonlist "ID" Such as : rdr.ID = "rdlAnswer"

then use "FindControl" function to find the control by "ID"

RadioButtonList rdr =  (PlaceHolder1.FindControl("rdlAnswer")) as RadioButtonList;

Try it please.....
Member-2338430 22-Jun-14 13:51pm
ok but for example 5 question I have.all radiobuttonlist same ID rdlAnswer?????
how to get all radiobuttonlist selected value?

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