Question

I am using ASP.NET Web Forms/C#.

I am having this function in my code behind which fills Cities DropDownList based on the State DropDownList selection.

Here is my function.

public void CityFill(int index,int id)
        {
            //This function calls GetCities method which will get all cities of a state.
            var city = CustomerBLL.GetCities(index);



            //If id=0 then clear all dropdown before filling
            //or else they get appended.
            if (id == 0)
            {
                NewCustomerddlResidentialCity.Items.Clear();
                NewCustomerddlOfficeCity.Items.Clear();
                NewCustomerddlNativeCity.Items.Clear();
                NewCustomerddlNomineeCity.Items.Clear();
            }
            else
            {
                //If 1 then clear residential city
                if(id==1)
                    NewCustomerddlResidentialCity.Items.Clear();

                //If 2 then clear Office city.
                if(id==2)
                    NewCustomerddlOfficeCity.Items.Clear();

                //If id=3 then clear Native City.
                if(id==3)
                    NewCustomerddlNativeCity.Items.Clear();

                //If id=4 then clear Nominee City
                if(id==4)
                    NewCustomerddlNomineeCity.Items.Clear();
            }

            //Loop through all the cities in st object
            foreach (var c in city)
            {
                //If id=0 then fill all dropdowns
                if (id == 0)
                {
                    NewCustomerddlResidentialCity.Items.Add(c.city_name.Trim());
                    NewCustomerddlOfficeCity.Items.Add(c.city_name.Trim());
                    NewCustomerddlNativeCity.Items.Add(c.city_name.Trim());
                    NewCustomerddlNomineeCity.Items.Add(c.city_name.Trim());
                }
                else
                {
                    //If 1 then fill Res City
                    if(id==1)
                    NewCustomerddlResidentialCity.Items.Add(c.city_name.Trim());

                    //If 2 then fill Off City
                    if(id==2)
                    NewCustomerddlOfficeCity.Items.Add(c.city_name.Trim());

                    //If 3 then fill nat city
                    if(id==3)
                    NewCustomerddlNativeCity.Items.Add(c.city_name.Trim());

                    //If 4 then fill nominee city
                    if(id==4)
                    NewCustomerddlNomineeCity.Items.Add(c.city_name.Trim());

                }
            }
        }

The arguments passed to the function are index and id. index is SelectedIndex of State DropDownList. id is which City DropDownList needs to be filled.

Here is BLL class

namespace CwizBankApp
{
    public class CustomerBLL
    {
        public IList<mem_city> GetCities(int index)
        {
            using (var db = new DataClasses1DataContext())
            {
                var city = db.mem_cities.Where(c => c.state_id.Equals(index)).ToList();
                return city;
            }
        }
    }
}

I need to move the function from code behind to BLL class.

How do I go about this.

Can anyone help me out with this? Any suggestions are welcome.

Was it helpful?

Solution

I would suggest not to perform that in the BLL Class. DON'T FORCE IT to BLL as is designed to seperate the data access logic from the presentation logic.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top