2011-11-26 5 views
0

BLL 및 DAL 클래스를 사용하여 pageload의 드롭 다운을 채우고 싶습니다. 이 코드BLL에서 드롭 다운이 채워지지 않습니다

Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs)  Handles Me.Load 
     dropBrand.DataSource = BLLManufacturer.selectManufacturers() 
     dropBrand.DataTextField = "ManufacturerName" 
     dropBrand.DataValueField = "ManufacturerID" 
     dropBrand.DataBind() 

     dropModel.DataSource = BLLModel.selectModelsByBrand(Convert.ToInt16(dropBrand.SelectedValue)) 
     dropModel.DataTextField = "ModelName" 
     dropModel.DataValueField = "ModelID" 
     dropModel.DataBind() 
    End Sub 

가 어떻게해야대로 첫 번째 드롭 다운 브랜드로 채워이지만, 두 번째는하지 않습니다. 두 번째 드롭 다운은 첫 번째 드롭 다운에서 선택한 브랜드의 자동차 모델을 표시해야합니다. 그러나 dropBrand.SelectedValue는 내가 선택한 모든 브랜드를 항상 0으로 반환합니다. 변환하지 않고도 toint16 나 notint toint32 또는 toint64로 변환합니다. 누구든지이 문제를 해결하는 방법을 알고 있습니까?

답변

0

드롭 다운 목록에 초기 데이터 바인딩 만 수행하면 작업 한 내용이 작동하지 않습니다.

BLLManufacturer 드롭 다운 목록에 대해 실행되는 이벤트를 설정 한 다음 해당 목록에서 선택한 값을 가져와 데이터를 BLLModel 목록에 바인딩해야합니다. 이 (코드는 테스트하지) 대략 같은 -

Private Sub BLLManufacturer_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles BLLManufacturer.SelectedIndexChanged 
     ' Get the currently selected item in the ListBox. 
     Dim curItem As String = BLLManufacturer.SelectedItem.ToString() 

     dropModel.DataSource = BLLModel.selectModelsByBrand(Convert.ToInt16(curItem)) 
     dropModel.DataTextField = "ModelName" 
     dropModel.DataValueField = "ModelID" 
     dropModel.DataBind() 
End Sub 

당신은 또한 당신이 AJAX를 통해 원하는 것을 다시 페이지에 게시를 방지 할 수있다.

관련 문제