• 博客园logo
  • 会员
  • 众包
  • 新闻
  • 博问
  • 闪存
  • 赞助商
  • HarmonyOS
  • Chat2DB
    • 搜索
      所有博客
    • 搜索
      当前博客
  • 写随笔 我的博客 短消息 简洁模式
    用户头像
    我的博客 我的园子 账号设置 会员中心 简洁模式 ... 退出登录
    注册 登录
Butterfly
博客园    首页    新随笔    联系   管理    订阅  订阅
DropDownList 数据绑定
     第一种:   
    
  DataSet   ds=   new   DataSet();      
  ds   =   cls2.SelectOle();  
  DropDownList1.DataSource   =   ds.Tables["My"].DefaultView;          
  DropDownList1.DataTextField   =   "dep_Name";      
  DropDownList1.DataValueField   =   "dep_Id";      
  DropDownList1.DataBind();    
   
  第二种:  
   
  DataSet   set1=   new   DataSet();    
  set1   =   cls2.SelectOle();  
  for   (int   num1   =   0;   num1   <   set1.Tables["My"].Rows.Count;   num1++)  
  {  
  DropDownList1.Items.Add(set1.Tables["My"].Rows[num1][1].ToString());  
  }  
   
  <asp:DropDownList   id="DropDownList1"     DataValueField="dep_Id"   DataTextField="dep_Name"   runat="server"></asp:DropDownList>  
第一种是直接绑定数据集中的内容,第二种除了绑定数据集内容,还可以加入自定义的选项
posted on 2009-02-23 12:07  butterfly  阅读(313)  评论(0)    收藏  举报
刷新页面返回顶部
博客园  ©  2004-2025
浙公网安备 33010602011771号 浙ICP备2021040463号-3