asp.net add DropDownList control code to Updatepaneel dynamically

Source: Internet
Author: User

ASP tutorial. NET dynamically add DropDownList control code to Updatepaneel

aspx file, add the code as above, the Showchildlist function is as follows:
protected void Showchildlist (object sender, EventArgs e)
{
DropDownList Ddl_now = (DropDownList) sender;
String sql = "Select Part_id,part_name from Tb_parts where root_id= '" + ddl_now.selectedvalue.tostring () + "'";
SqlDataReader dr = means.getcom (SQL);
if (dr.hasrows)
{
DropDownList ddl_new = new DropDownList ();
Ddl_new.selectedindexchanged + = new System.EventHandler (this.childlist);
Ddl_new.autopostback = true;
ListItem li = new ListItem ();
Li.value = "-1";
Li.text = "Please select column ...";
Li.selected = true;
Ddl_new.items.add (LI);
while (Dr.read ())
{
ListItem li2 = new ListItem ();
Li2.value = dr["part_id"].tostring ();
Li2.text = dr["Part_name"].tostring ();
Ddl_new.items.add (LI2);
}
Ddl_now.parent.controls.add (ddl_new);
}
}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.