简体   繁体   中英

Data not appearing in dropdownlist

Now I have double checked this, I have found it was just bad positioning, but now I am coming up with the error of the data not being added to the box and it's just displaying blank on the page, not even the "empty" text is appearing in it but the data is being found as it is displaying when I am debugging and hitting the adding part

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();
        }
    }
}

The ASP.NET

<needlesports:BrandDropDownList runat="server" Visible="true"  />

You don't need this line;

      DropDownList brandDropDownList = new DropDownList();

There is no need to be creating a new instance of a DropDownList within a DropDownList .

You should be just doing this;

this.Items.Add(brand.Name);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM