日期:2011-04-02 浏览次数:20522 次
用绑定一个 DataList 的三层代码说明一下:
DAL 数据访问层代码:
------------------------------------------------------------
//绑定IDList,显示所有人员列表
public DataSet SelectIDListAll()
{
string Str = "select p_number,p_name from t_people";
DataSet ds = new DataSet();
myCon = new SqlConnection(DAL.DALConfig.ConnectionString);
try
{
SqlDataAdapter mycomm = new SqlDataAdapter(Str,myCon);
mycomm.Fill(ds,"t_people");
return ds;
}
catch(Exception exc)
{
throw exc;
}
}
BLL业务层代码:
----------------------------------------------------------------
//绑定IDList,显示所有人员列表
public ArrayList SelectIDListAll()
{
DAL.TPeopleDao peopledao = new TPeopleDao();
DataSet ds = new DataSet();
ds = peopledao.SelectIDListAll();
// Creates and initializes a new ArrayList.
ArrayList myAL = new ArrayList();
for(int i=0;i<ds.Tables[0].Rows.Count;i++)
{
myAL.Add(ds.Tables[0].Rows[i][0].ToString() + " " +ds.Tables[0].Rows[i][1].ToString() );
}
return myAL;
}
页面层代码:
-----------------------------------------------------------------
//绑定IDList,显示所有人员列表
private void SelectIDListAll()
{
Lab.BLL.TPeopleBiz peoplebiz = new TPeopleBiz();
ArrayList myAL = peoplebiz.SelectIDListAll();
this.P_IDlist.Items.Clear();
for(int i = 0 ;i<myAL.Count;i++)
{
this.P_IDlist.Items.Add(myAL[i]);
}
}