现在我已经仔细检查了这一点,我发现这只是错误的定位,但现在我想出的数据没有被添加到框中的错误,它只是在页面上显示空白,甚至不是“空的“文本出现在其中,但是当我正在调试并点击添加部分时,正在显示数据
public class BrandDropDownList : DropDownList
{
protected override void OnLoad(EventArgs e)
{
BrandListRetrieve();
base.OnLoad(e);
}
public void BrandListRetrieve()
{
var factory = new BrandFactory();
var customBool1State = factory.ByCustomBoolean1(true, CoreHttpModule.Session);
if (customBool1State != null)
{
var brandDropDown = CoreHttpModule.Session.CreateCriteria(typeof(Brand)).List<Brand>();
DropDownList brandDropDownList = new DropDownList();
foreach (Brand brand in brandDropDown)
{
brandDropDownList.Items.Add(brand.Name);
}
if (brandDropDownList.Items.Count < 0)
{
brandDropDownList.Items.Insert(0, new ListItem("Hello World", "Hello World"));
}
brandDropDownList.DataBind();
}
}
}
ASP.NET
<needlesports:BrandDropDownList runat="server" Visible="true" />
答案 0 :(得分:3)
你不需要这一行;
DropDownList brandDropDownList = new DropDownList();
无需在DropDownList
内创建DropDownList
的新实例。
你应该这样做;
this.Items.Add(brand.Name);