2012-10-02 4 views
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" /> 
+0

DropDownList에 직접 항목을 추가하기 때문에 DataBind() 단계가 필요하다고 생각하지 않습니다. – tomasmcguinness

+0

이봐, 나는 실제로 이것을 제거했다 :) 나는 나 자신을 알아 차 렸지만 아무런 차이가없는 것처럼 보였다. –

+1

WPF 일명 Windows Presentation Foundation이 ASP.NET Webform과 동일하지 않다는 것을 알고 계십니까? 질문에 다시 태그를 답니다. – nemesv

답변

3

당신을 디버깅 및 타격하고 때 표시 될 때 데이터가 발견되고있다 이 줄은 필요 없다.

 DropDownList brandDropDownList = new DropDownList(); 

DropDownListDropDownList의 새로운 인스턴스를 생성 할 필요가 없습니다.

이렇게하면됩니다.

this.Items.Add(brand.Name); 
+0

안녕하십니까.이 문제는 최종적으로 해결되었습니다. –

관련 문제