110,499
社区成员
发帖
与我相关
我的任务
分享
public class UserTypeDropDownList : DropDownList
{
private bool inited = false;
public override ListItemCollection Items()
{
if(!inited)
{
inited = true;
this.Items.Add(new ListItem("请选择", ""));
foreach (UserType t in LpHey.SQLServerDAL.Factory.getUserTypeDAL().getAllUserType())
{
this.Items.Add(new ListItem(t.TypeName, t.TypeID.ToString()));
}
}
return base.Items;
}
}
不管如何写,基本思路就是——不要写在实例化方法里!public class UserTypeDropDownList : DropDownList
{
private bool inited = false;
public override ListItemCollection Items()
{
if(!inited)
{
inited = true;
this.Items.Add(new ListItem("请选择", ""));
foreach (UserType t in LpHey.SQLServerDAL.Factory.getUserTypeDAL().getAllUserType())
{
this.Items.Add(new ListItem(t.TypeName, t.TypeID.ToString()));
}
}
}
}