Search code examples
c#asp.netdata-binding3-tier

how to bind dropdown in 3-tier architecture


how the dropdown needs to be bound in professinal way? Does DropDown component need to be passed to BAL(business access layer)?

Please provide some code snippet and reference links..


Solution

  • I usually will have a method in my Business Layer which returns a List of Custom class ( Ex : for State, I will have a State Class which has public properties like ID,Name,Code) .Then i will bind that to the drop down list

                List<State> objLstState =new List<State>();
                objLstState = StateManager.GetStates();  //This method returns a list of States
                if(objLstState!=null && objListState.Count>0)
                {
                  dropDownSchoolState.DataSource = objLstState;
                  dropDownSchoolState.DataTextField = "Name";
                  dropDownSchoolState.DataValueField = "ID";
                  dropDownSchoolState.DataBind();
                }
    

    The above code executes in my UI layer (in a codebehind of an aspx page)