我正在使用ASP.NET Web Forms/C#.
我正在使用此功能DropDownLists根据从州中选择的州填充城市。州和城市DropDownList有 3 个DropDownLists。(住宅、本地、办公室)。
这是我的功能。
public void CityFill(int index,int id)
{          
    var city = CustomerBLL.GetCities(index);
    //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());
        }
    }
}
DropDownLists这个基于 id 的函数将根据 id 参数填充适当的城市。
这是目前在。code behind我的问题是是否应该在这里使用这个功能,或者我应该把它移到我的Business Logic class. 这是我的CustomerBLL.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Drawing;
using System.Text.RegularExpressions;
using System.Data.SqlClient;
using System.Threading;
using System.Globalization;
using System.Web.Services;
using System.IO;
using System.Xml.Linq;
using System.Web.Security;
using System.Text;
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;
            }
        }
    }
}
什么是正确的方法。有人可以指导我吗?
欢迎任何建议。