Hello World
Hello World

Reputation: 1437

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

Upvotes: 0

Views: 112

Answers (1)

saj
saj

Reputation: 4796

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

Upvotes: 3

Related Questions