pwqzc

DrpDownList数据绑定方法

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();

发表于 2005-10-14 14:36  一帆(老鼠粮仓之路)  阅读(465)  评论(1编辑  收藏  举报
 

分类:

技术点:

相关文章:

  • 2022-01-07
  • 2021-12-12
  • 2022-01-31
  • 2021-12-26
  • 2022-12-23
  • 2021-11-13
  • 2022-02-08
  • 2021-07-23
猜你喜欢
  • 2021-12-07
  • 2021-08-21
  • 2021-11-07
  • 2021-12-06
  • 2021-12-26
  • 2021-10-25
  • 2022-12-23
相关资源
相似解决方案