我在页面使用了大量的DropDownList控件,所有控件的Items都动态使用数据表进行绑定,我现在想使用一个公共的函数来为所有的DropDownList添加一个空行,如何实现? protected void InsertEmptyLine(object sender,EventArgs e)
{
控件ID.Items.Insert(0, new ListItem("", ""));
}就是如何获取上面代码中的控件ID?请帮忙
{
控件ID.Items.Insert(0, new ListItem("", ""));
}就是如何获取上面代码中的控件ID?请帮忙
Control _Control = (Control)sender;
_Control.ID
protected void InsertEmptyLine()
{
foreach (Control ctl in this.form1.Controls)
{
if (ctl.GetType() == new DropDownList().GetType())
{
((DropDownList)ctl).Items.Insert(0, new ListItem("dd", "dd"));
}
}
}