惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

Google DeepMind News
Google DeepMind News
aimingoo的专栏
aimingoo的专栏
爱范儿
爱范儿
D
Docker
I
InfoQ
Microsoft Security Blog
Microsoft Security Blog
G
Google Developers Blog
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
Vercel News
Vercel News
H
Hackread – Cybersecurity News, Data Breaches, AI and More
T
Tailwind CSS Blog
D
DataBreaches.Net
月光博客
月光博客
N
Netflix TechBlog - Medium
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
V
Visual Studio Blog
MyScale Blog
MyScale Blog
B
Blog
阮一峰的网络日志
阮一峰的网络日志
L
LangChain Blog
Recent Announcements
Recent Announcements
Microsoft Azure Blog
Microsoft Azure Blog
WordPress大学
WordPress大学

博客园 - 阿社

!!如何看到真实的服务器 错误提示 !访问网站出现Directory Listing Denied 是什么原因? !后台登录总 提示验证码错误!! !设置IIS后 访问提示 页面不存在 HTTP 500错误 Windows2003网络服务器安全攻略! Win2003 ISS下Asp配置技巧 http 500内部服务器错误 !商城登录后不能自动在社区登录! ASP.NET中TreeView控件使用小结 使用IE WebControls中的TabStrip控件和MultiPage控件实现选项卡式风格页面 [程序员必看]请不要做浮躁的人 未能在设计视图中打开,在中以不同方式将值括起来 我应该用DataReader类还是DataSet类呢?” DataGrid、DataList和Repeater控件 ListBox控件使用 C#笔记 C#常用函数和方法集汇总-日期函数 ASP常用三十三种代码 ASP.net数据绑定概述和语法 编程控制控件Style属性
DropDownList控件使用
阿社 · 2006-09-02 · via 博客园 - 阿社

DropDownList控件与RadioButtonList控件相似。DropDownList表示一组相互排斥的选项。可以通过三种方式添加选项到DropDownList:在声明DropDownList时列出选项(即在HTML代码中或借助属性编辑器添加);直接往DropDownList控件的ListItemCollection集合中添加项(如下例1、列2);绑定DropDownList到数据源(例3)。
例1:
  private void Page_Load(object sender, System.EventArgs e)
  {   this.DropDownList1.Items.Add("一");
   Response.Write(this.DropDownList1.SelectedValue);//等同于this.DropDownList1.SelectedItem.Value
  }//此时Value属性同步与Text属性 显示结果为:一  ;SelectedIndex值为0;
例2:protected System.Web.UI.WebControls.DropDownList DropDownList1;
 
  private void Page_Load(object sender, System.EventArgs e)
  {   ListItem li =new ListItem();
   li.Text="一";
   li.Value="1";  
   this.DropDownList1.Items.Add(li);//或可以采取 this.DropDownList1.Items.Add(new  ListItem("一","1"))
   Response.Write(this.DropDownList1.SelectedItem.Value);
}/此时Value属性为1,Text属性为一 显示结果为:1  ;SelectedIndex值为0;

例3:
protected System.Web.UI.WebControls.DropDownList ddlShengOld;
  string strSql="select sheng,shengid from t_sheng";
   SqlDataReader sdr=Auiso.Base.ExecuteSql_sdr(strSql);
   this.ddlShengOld.DataSource=sdr;
   this.ddlShengOld.DataTextField="sheng";//对应Text
   this.ddlShengOld.DataValueField="shengid";//对应Value  不显示出来
   this.ddlShengOld.DataBind();
例4:初始化选定某个值的方法
foreach (ListItem li in this.ddlist)
   {
    if (li.Value=="设定值")
    {
     li.Selected=true;
    }
   }
或使用DropDownList1.SelectedIndex   =   DropDownList1.Items.IndexOf(DropDownList1.Items.FindByText(str1))

例5:实现联动
在该控件的CheckedChanged事件编程,并将AutoPostBack属性设置为True
例6:实现ListBox或DropDownList之间项目转移 
用this.ListBox1.SelectedIndex=-1;
   this.ListBox1.Items.Add(this.DropDownList1.SelectedItem);
   this.DropDownList1.Items.Remove(this.DropDownList1.SelectedItem);
ListBox 可以通过ListSelectionMode 设置多选,默认值为 Single

posted on 2006-09-02 10:14  阿社  阅读(1618)  评论()    收藏  举报