在业务层中使用列表集合时,在演示层中绑定列表控件 [英] Bind List Control in Presentation Tier While using List collection in Business tier
问题描述
大家好,
在这里,我遇到了一个问题,我在Web应用程序中使用了3层体系结构,我有一种使用界面,属性类显示记录的方法,如下所示:
Hi everybody,
here i have a problem i''m using 3 tier architecture in my web application i have a method to display the record using interface, property class like below :
public List<EmpPrp> DispEmp()
{
ConOpen();
SqlCommand cmd = new SqlCommand("dispemp", con);
cmd.CommandType = CommandType.StoredProcedure;
SqlDataReader dr = cmd.ExecuteReader();
List<EmpPrp> obj = new List<EmpPrp>();
while (dr.Read())
{
EmpPrp k = new EmpPrp();
k.EmpCod = Convert.ToInt32(dr[0]);
k.EmpNam = dr[1].ToString();
obj.Add(k);
}
dr.Close();
cmd.Dispose();
con.Close();
return obj;
}
我正在业务层中使用列表集合,现在我想将我的Presentation Tier中的列表控件与具有编码的数据库绑定在一起,我可以通过使用Object DataSource来实现,但我想通过编码来实现.您能帮我解决这个问题吗,我对此一无所知.
在此先感谢您.
i am using list collection in business tier, now i want to bind my list control in Presentation Tier with the data base with coding i can do so by using Object DataSource but i want to do it with coding. Can you plz help me on this topic, I have no knowlede about it.
Thanks in advance.
推荐答案
您可以只使用
You can just use
myList.DataSource = yourEmpList;
myList.DataTextField = "EmpNam";
myList.DataValueField = "EmpCode";
myList.DataBind();
在您的Page_Load或类似文件中.
希望对您有帮助
in your Page_Load or similar.
Hope this helps
这篇关于在业务层中使用列表集合时,在演示层中绑定列表控件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!