1,
SqlDataReader dr = comm.ExecuteReader();
//循环dr,给dListParent添加条目
while(dr.Read())
{
dListChild.Items.Add(new ListItem(dr[1].ToString(),dr[0].ToString()));
//也可以这样
//dListParent.Items.Add(new ListItem(dr["phone_text"].ToString(),dr["phone_value"].ToString()));
}
这样绑定效能高点,且灵活的添加特殊的条目如在while前加:
dListChild.Items.Add(new ListItem("全部选择","0"));
2,
SqlDataAdapter myAdapter = new SqlDataAdapter(myCommand);
DataTable dt = new DataTable();
myAdapter.Fill(dt);
// 数据绑定 DropDownList 控件
DropDownList1.DataSource = dt;
DropDownList1.DataTextField = "ProductName";
DropDownList1.DataValueField = "UnitPrice";
DropDownList1.DataBind();