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>  
第一种是直接绑定数据集中的内容,第二种除了绑定数据集内容,还可以加入自定义的选项

转载于:https://www.cnblogs.com/butterfly/archive/2009/02/23/1396360.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值