现在我仔细检查了这个,我发现它只是定位不好,但现在我想出了数据没有添加到框中的错误,它只是在页面上显示空白,甚至没有“空”文本出现在其中,但是在我调试并点击添加部分时正在显示数据
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" />