0

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

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"  />
4

1 回答 1

3

你不需要这条线;

      DropDownList brandDropDownList = new DropDownList();

无需在 a 中创建 a 的新DropDownList实例DropDownList

你应该这样做;

this.Items.Add(brand.Name);
于 2012-10-02T08:57:35.303 回答