我的应用程序是用三层架构构建的。但是,我希望下拉列表将数据源提供给 Value Object 类。目前,我正在从数据访问层 -> 业务逻辑层 -> 表示层获取下拉列表的数据。但我想从值对象中获取列表的数据源。因此,我想要的是来自数据访问层 -> 值对象 -> 业务逻辑层 -> 表示层(下拉菜单)。我试图将它数据源到值对象,但它给了我“无效数据源;必须是 IListSource、IEnumerable 或 IDataSource 类型”的错误。谢谢!
这是我的代码:
宗教VO
public class ReligionVO
{
private string religionCode;
public string ReligionCode
{
get { return religionCode; }
set { religionCode = value; }
}
private string religion;
public string Religion
{
get { return religion; }
set { religion = value; }
}
}
宗教道
public class ReligionDAO
{
private DB db = new DB();
public DataTable SelectAllReligion()
{
return db.GetData("SELECT * FROM Religions");
}
}
宗教BLO
public class ReligionBLO
{
private ReligionVO religionVO = new ReligionVO();
private ReligionDAO religionDAO = new ReligionDAO();
public DataTable SelectAllReligion()
{
return religionDAO.SelectAllReligion();
}
/* this is the code I tried to datasource to the Value Object
public ReligionVO SelectAllReligion()
{
dt = religionDAO.SelectAllReligion();
foreach (DataRow dr in dt.Rows)
{
religionVO.ReligionCode = dr["religion_code"].ToString();
religionVO.Religion = dr["religion"].ToString();
}
return religionVO;
}
*/
}
ASPX
ddlReligion.DataSource = religionBLO.SelectAllReligion();
ddlReligion.DataValueField = "religion_code";
ddlReligion.DataTextField = "religion";
ddlReligion.DataBind();
这是错误消息的屏幕截图: