Runtime error code while retrving value from dropdownlist

Reply Forum
Forum postanant @ 2011-10-27 16:49:48
ReplyReply to
DropDownList d = (DropDownList)Panel3.FindControl("Text" + i);
value = d.SelectedValue.ToString();


"Object reference not set to an instance of an object." above code is written in second button.
in first buttion i created dynamically dropdownlist

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("anant");
d.Items.Add("Gautum");

//d.SelectedIndexChanged += new EventHandler(d_SelectedIndexChanged);


Panel3.Controls.Add(d);
Panel3.Controls.Add(l1);

con1.Close();
}











© net-tutorials.com 2006 - 2012

MailContact net-tutorials.com