First in web form THere will appear one textbox and button. enter the number in textbox and press the button.Pressing button create Dynamically t number of dropdownlist as entered in textbox.I successful do it .But when i what use the seletedvalue of dropdownlist I cannot through anthor buttton .
I have globally declare dropdownlist object d;
Dropdownlist d;
protected void Button1_Click(object sender, EventArgs e)
{
int a = Convert.ToInt32(TextBox1.Text);
for (int i = 0; i < a; i++)
{
d = new DropDownList();
d.ID = "Text" + i;
LiteralControl l1 = new LiteralControl("<br></br>");
SqlConnection con1 = new SqlConnection("Data Source=ABC-0D30299B90A;Initial Catalog=JAPIT;Integrated Security=True");
con1.Open();
d.Items.Add("amit");
d.Items.Add("asas");
Panel3.Controls.Add(d);
Panel3.Controls.Add(l1);
con1.Close();
}
}
protected void Button2_Click(object sender, EventArgs e)
{
int a = Convert.ToInt32(TextBox1.Text);
string value = "";
for (int i = 0; i < a; i++)
{
//d = new DropDownList();
value = d.SelectedValue.ToString();
//DropDownList d = new DropDownList();
//DropDownList dr = (DropDownList)Session["Product" + i];
//dr = (DropDownList)Session["Productid" + i];
//dr.ID = "Text" + i;
//value = dr.SelectedValue();
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();
}
}