Click here to Skip to main content
15,891,184 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
hello

i want to create a dynamic controls depended on value comes from dgh

here is my code
C#
cn = new SqlConnection(ConfigurationManager.ConnectionStrings["lap_connection"].ConnectionString);
            cmd = new SqlCommand("SELECT COUNT( pat_id) AS patient_test FROM patient_test_data WHERE dbo.patient_test_data.test_date >= cast(getdate() as Date) AND dbo.patient_test_data.pat_id = 4;", cn);
            cmd.CommandType = CommandType.Text;
            cmd.Connection.Open();
            dr = cmd.ExecuteReader(CommandBehavior.CloseConnection);
            while (dr.Read())
            {
                int number_test = int.Parse(dr["patient_test"].ToString());
                for (int number = int.Parse(dr["patient_test"].ToString()); number <= number_test; number++)
                {
                    TextBox txt = new TextBox();
                    //txt.Text = dr["Col1"].ToString();
                    TextBox txt2 = new TextBox();
                    //txt2.Text = dr["Col2"].ToString();
                    TextBox txt3 = new TextBox();
                    //txt3.Text = dr["Col3"].ToString();
                    this.Controls.Add(txt);
                    this.Controls.Add(txt2);
                    this.Controls.Add(txt3);
                }
            }


but i got error can i get some help plz and how to insert to database from those dynamic controls
thanks in advanced
Posted
Updated 8-Feb-14 6:29am
v2

Quote:
textghox txt = new textghox();
What is a 'textghox'? Do you mean TextBox[^]?
 
Share this answer
 
Comments
Abdullaziz Said 8-Feb-14 12:30pm    
yes sorry this is chrome extension changed some thing in the code
use Page_init for getting the values of dynamic created controls in post back.
check this Dynamic controls retain after postback[^]
 
Share this answer
 
Comments
Abdullaziz Said 9-Feb-14 9:01am    
i want to know how to create them first :)

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