Dropdownlist d; Dropdownlist dr; this decalre global. in inside button1 use For loop for (int i = 0; i < a; i++) { d = new DropDownList(); d.ID = "Text" + i; d.Items.Add("amit"); d.Items.Add("asas"); Panel3.Controls.Add(d); } }
string value = ""; for (int i = 0; i < a; i++) { dr = (DropDownList)Panel3.FindControl("Text" + i); value = dr.SelectedValue.ToString(); SqlConnection con = new SqlConnection("Data Source=ABC-0D30299B90A;Initial Catalog=IT;Integrated Security=True"); con.Open(); SqlCommand cmd1 = new SqlCommand("insert into niitstud values('" + value + "')", con); cmd1.ExecuteNonQuery(); con.Close(); } DropDownList d = (DropDownList)Panel3.FindControl("Text" + i); value = d.SelectedValue.ToString();
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)