asp教程.net 向updatepaneel中动态添加dropdownlist控件代码
//aspx文件中添加如上代码,showchildlist函数如下:
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 = "请选择栏目...";
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);
}
}